Interference from Modal Overlay Disrupts functionality of other Links on Shared Page

My primary webpage consists of multiple links, including one that triggers a modal when clicked on. This modal opens on top of the main page, allowing me to compare expected and actual links. However, I encounter difficulty in comparing the rest of the links as they open their content in a separate window. Notably, the HTML does not incorporate any IFRAME tags.

Thank you,

<span id="ctl00_ContentPlaceHolder1_ExpirationDate" class="ExpirationDateSkin">
    <span class='topCopy'>Enter your account # below and<br />click "Register" <br /> to take advantage of this promotion.
    </span><div class='learnMoreLink'>
    <span class='adaScnReaderText'>open overlay 
   </span>
    <a href='#'>Learn More</a></div></span>

Below is the requested code. Please refer to the preceding question for context. Thanks,

 String mainWindowHandle=driver.getWindowHandle();

 driver.findElement(By.xpath("//span[@id='ctl00_PlaceHolder1_ExpirationDate']/div/a")).click();

 Set s = driver.getWindowHandles();
 Iterator i = s.iterator();
 while(i.hasNext())
 {
     String popupHandle=i.next().toString();
     if(!popupHandle.contains(mainWindowHandle)) {

         driver.switchTo().window(popupHandle);
      }

      driver.findElement(By.xpath("//div[@id='enroll']/div/div/a")).click(); 
 }

Answer №1

There are various ways to navigate to a different location on a webpage.

Here are some examples:

  • driver.get(...)
  • driver.switchTo().frame(...)
  • driver.switchTo().window(...)
  • driver.switchTo().defaultContent()
  • driver.findElement(...).click()
  • driver.navigate().back()
  • driver.navigate().forward()
  • driver.navigate().to(...)
  • driver.navigate().refresh()

However, navigating to a different location can cause elements from the previous DOM to become "stale". To prevent this in your specific scenario, first save a list of all relevant window handle strings:

List<String> handles = new ArrayList<String>();
Set s = driver.getWindowHandles();
Iterator i = s.iterator();
while (i.hasNext())
{
    String popupHandle = i.next().toString();
    if (!popupHandle.contains(mainWindowHandle))
        handles.add(popupHandle);
}

Then, switch to each window and perform actions on that window:

for (String handle : handles)
{
    driver.switchTo().window(handle);
    // Perform actions here
    driver.switchTo().defaultContent();
}

It's important to note that on certain web pages, window-handle names may change as you navigate through the page. This situation can be managed with some complexity; feel free to ask for assistance if needed...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for waiting on image loading in canvas

My challenge involves interacting with the image loaded on a canvas. However, I am uncertain about how to handle waiting for the image to load before starting interactions with it in canvas tests. Using driver.sleep() is not a reliable solution. Here is ...

Error: Unsupported Media Type when attempting to send JSON data from an AngularJS frontend to a Spring controller

Below is the controller function code snippet @RequestMapping(value = "/logInChecker", method = RequestMethod.POST, consumes = {"application/json"}) public @ResponseBody String logInCheckerFn(@RequestBody UserLogData userLogData){ Integer user ...

Generating a tree structure using a JavaScript array

Looking to build a tree structure from a given list of data where the paths are represented like: A-->B-->C-->D-->E.. A-->B-->C-->D-->F.. A-->F-->C-->D-->E.. . . . All possible data paths are stored in an array. The de ...

The AJAX response consistently returns a 405 status code

I am experiencing an issue with an AJAX post request. $.ajax({ type: "POST", contentType: "application/json", url: "/rating/save", data: JSON.stringify(rating), dataType: "json", mimeType: "application/json" ...

Unsuccessful Invocation of Servlet by Ajax Function

I have a situation where I am trying to trigger an Ajax javascript function from my jsp file, with the intention of loading a servlet for further processing. The issue I am facing is that even though I am able to pass values from the jsp to the ajax functi ...

Output a message to the Java console once my Selenium-created Javascript callback is triggered

My journey with Javascript has led me to mastering callback functions and grasping the concept of 'functional programming'. However, as a newcomer to the language, I struggle to test my syntax within my IntelliJ IDE. Specifically, I am working on ...

Transforming JSON data into a visually appealing pie chart using highcharts

I'm having trouble loading my JSON string output into a highcharts pie chart category. The chart is not displaying properly. Here is the JSON string I am working with: var json = {"{\"name\":\"BillToMobile\"}":{"y":2.35},"{\ ...

Selenium in C#: Timeout issue with SendKeys and Error thrown by JS Executor

Attempting to insert the large amount of data into the "Textarea1" control, I have tried two different methods. The first method successfully inserts the data but occasionally throws a timeout error, while the second method results in a JavaScript error. A ...

Combining a JavaScript NPM project with Spring Boot Integration

Recently, I built a frontend application in React.js using NPM and utilized IntelliJ IDEA as my IDE for development. Additionally, I have set up a backend system using Spring Boot, which was also developed in IntelliJ IDEA separately. My current goal is t ...

Executing selenium tests on Internet Explorer 11 on a Windows 10 1809 machine without encountering any new pop-up windows

While testing on my computer, I encountered an issue where my test would start successfully, but after opening and closing several Internet Explorer windows during the test, no new windows would open. There were no error messages displayed, and the test se ...

Guide on filling in credentials in Facebook popup using Webdriver with Javascript

On my website, I have a feature where users can authenticate using Facebook. Currently, my site is not public, but you can see a similar process in action at agar.io. Just click on "Login and play" and then click on "Sign in with Facebook". This will open ...

Having trouble with accessing an element that contains both onclick and text attributes in Selenium Webdriver?

The HTML code I'm dealing with includes this element: <a style="text-decoration:none; font-weight:normal;" href="javascript:void(0);" onclick="CreateNewServiceItemApproved();"> <img src="icons/ui/addnew.png"> <span style="color:# ...

What is the best way to extract the singular PDF link from a webpage?

Currently, I am attempting to utilize Selenium in Java to access DOM elements. However, I have encountered an issue while testing the code: Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is n ...

Comparing front end automation between JavaScript and Java or Ruby

Could you provide some insights on why utilizing a JS framework like webdriverio is preferred for front end automation over using Selenium with popular languages like Java or Ruby? I understand that webdriverio and JS employ an asynchronous approach to fr ...

Tips for effectively managing dynamic xpaths

When conducting a search operation, I am required to select the text that is returned as a result. Each search will produce different xpaths. Below are examples of various xpaths returned during a search: .//*[@id='messageBoxForm']/div/div[1]/di ...

I must interact with the video within the iframe by clicking on it

I am trying to interact with an iframe video on a webpage. Here is the code snippet for the video: <div class="videoWrapper" style="" xpath="1"> <iframe width="854" height="480" src="xxxxxxx" frameborder="0" allow="autoplay; encrypted-media" all ...

Steps for creating an HTML report using Intern JS

Our team relies on intern JS for automating functional tests, however we are facing difficulty in generating an html report. I attempted to use locvhtml as suggested by the Intern documentation (https://theintern.github.io/intern/#reporter-lcov), but unfo ...

Understanding Java and JavaScript variables within a JSP webpage

I am currently working on populating a pie chart from Google with data fetched from my database. Although I have successfully retrieved the desired results in my result set, I am facing challenges in converting my Java variables into JavaScript variables ...

Ordering and displaying data with AngularJS

Trying to maintain a constant gap of 5 between pagination elements, regardless of the total length. For instance, with $scope.itemsPerPage = 5 and total object length of 20, we should have 4 pages in pagination. However, if $scope.itemsPerPage = 2 and tota ...

Unable to locate and interact with a concealed item in a dropdown menu using Selenium WebDriver

Snippet: <select class="select2 ddl visible select2-hidden-accessible" data-allow-clear="true" id="Step1Model_CampaignAdditionalDataTypeId" multiple="" name="Step1Model.CampaignAdditionalDataTypeId" tabindex="-1" aria-hidden="true"> <option value ...