1
votes

I am facing the below error!!

I am using Selenium WebDriver. Switching to a child window from parent and clicking a link on child, which redirects me to the earlier parent window with new url opened in it.

I need to switch to new Parent url in the same previous parent window but unable to do so.

any help much appreciated!!

Below is the code: driver.findElement(By.id("href_billing_&_reporting")).click();

    driver.findElement(By.linkText("Go to Billing Summary")).click();

    driver.findElement(By.linkText("01 Mar 2016")).click();

    Thread.sleep(5000);

    driver.findElement(By.linkText("AMS TAX")).click();

    driver.findElement(By.linkText("00842")).click();

    String Parenthandel = driver.getWindowHandle();

    for(String Child : driver.getWindowHandles()){

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

    driver.switchTo().frame("modalSubWindow");

        driver.findElement(By.linkText("View More Vehicle Details>>")).click();
        driver.switchTo().window(Parenthandel);

I tried with defaultcontent() method too but no luck!!

2
What is the error you are getting? - Akbar

2 Answers

0
votes

Since the parent window is navigating to a new URL, selenium is refreshing the parent window handle.

Try this solution.

  1. Save the child window handle
  2. Get all window handles once again after clicking "View More Vehicle" link
  3. Loop thru the handles and switch to the window which is not equal to child.
0
votes

Using Collection (Set), can save all available open window details..

driver.findElement(By.linkText("Go to Billing Summary")).click();

    driver.findElement(By.linkText("01 Mar 2016")).click();

    Thread.sleep(5000);

    driver.findElement(By.linkText("AMS TAX")).click();

    driver.findElement(By.linkText("00842")).click();

    Set<String> instancewindow= driver.getWindowHandles();
        Iterator<String> it = instancewindow.iterator();
        String parent =it.next();
        String child = it.next();
        driver.switchTo().window(child);

    driver.switchTo().frame("modalSubWindow");

        driver.findElement(By.linkText("View More Vehicle Details>>")).click();
        driver.switchTo().window(parent);