Could not able to navigate to the child browser window

75 views
Skip to first unread message

Biswajit Samal

unread,
Jul 18, 2014, 10:15:14 AM7/18/14
to seleniu...@googlegroups.com
Respected All,

I am facing a serious issue, After following all possible post related to this issue, still not able to figure it out . My problem is I am not able to switch to the child browser window hence can not able to perform an action on it.

My script is:-

 // Store and Print the name of the First window on the console
        String parentWindowHandle= driver.getWindowHandle();
        System.out.println("Parent window-->" +parentWindowHandle);

        // Click on the Button 
        driver.findElement(
By.xpath("html/body/div[1]/div[2]/div/div[2]/div/div[2]/form/div[13]/div[2]/span/ul/li/a"))
.click();

        // Store and Print the name of all the windows open              
        Set<String> WindowHandles = driver.getWindowHandles();
        System.out.println("All possible window-->" +WindowHandles);

        // Pass a window handle to the other window
        for (String childWindow : driver.getWindowHandles()) {
        System.out.println("Child window-->" +childWindow);
        driver.switchTo().window(childWindow);

// PERFORM THE ACTION IN NEW WINDOW
System.out.println("We are in second window");
driver.findElement(By.xpath("//td[@title='Vat UK']")).click();

        }

After clicking on the button a new browser window opens and that is the end of the story. It only gives the id of the parent window. 

If I manually click on the child window it works and test pass, shows all possible outputs.

Please help me, how to handle/solve this ..

ani0...@gmail.com

unread,
Jul 18, 2014, 3:19:46 PM7/18/14
to seleniu...@googlegroups.com
you need to use switch window function to go to pop up. By switching, u r just setting the context. u r storing parent window handle to switch back to parent after finishing pop up task

Cheers
Sent from BlackBerry10® on Airtel
From: Biswajit Samal
Sent: Friday 18 July 2014 7:45 PM
Subject: [selenium-users] Could not able to navigate to the child browser window

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7755219e-154b-47a1-af29-f3852304cdc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jianfeng Sun

unread,
Jul 20, 2014, 12:05:10 AM7/20/14
to seleniu...@googlegroups.com
You write driver.findElement(By.xpath("//td[@title='Vat UK']")).click(); within the for loop, which means it will try to click on such kind of element on each of the window under current webdriver instance, including the parent. If this element is not available on the first try, it will throw no such element exception.  ALWAYS READ THE ERROR MESSAGE AND THEN ASK THE QUESTION! 

If I am right till now, what I will do is to use title or URL to identify each window, stop the for loop on the page you want to continue your work. And then write the click method out of the loop, since you only want to click once. 

One more tip: when you do switch, the page load waiting may not enough, it will be safe if you can give a physical waiting time here to increase the reliability of your selenium script, like 2 secs. 

Seenu Vasu

unread,
Jul 20, 2014, 11:59:16 AM7/20/14
to seleniu...@googlegroups.com
Hi Samal, 
 
I tooo faced same problem for about 3 months and finally figured out....just replace your code like below

 // Store and Print the name of the First window on the console
        String parentWindowHandle= driver.getWindowHandle();

        // Click on the Button 
        driver.findElement(
By.xpath("html/body/div[1]/div[2]/div/div[2]/div/div[2]/form/div[13]/div[2]/span/ul/li/a"))
.click();

           
        Set<String> WindowHandles = driver.getWindowHandles();
        for (String childWindow : driver.getWindowHandles()) {
         if(!(parentWindowHandle.equals(childWindow)))   -----> Write this line exactly in your eclipse
{
            Thread.sleep(2000);
            driver.switchTo().window(childWindow);
             Thread.sleep(2000);
           driver.findElement(By.xpath("//td[@title='Vat UK']")).click();

}


        
         }







Let me know if the above code works...

Biswajit Samal

unread,
Jul 21, 2014, 2:07:40 AM7/21/14
to seleniu...@googlegroups.com
Hi Seenu,

Thanks for your valuable response, but the solution which you have provided is not working I stuck in the same scenario as previous.  The output in stack trace is  as follows:-
Parent window-->{355222fe-9a77-49db-91fa-d1746203a2fb}
All possible window-->[{355222fe-9a77-49db-91fa-d1746203a2fb}]

Hear the child window is not showing , hence it is not able to switch control to the child window.  
If you wish I can provide the HTML .

Seenu Vasu

unread,
Jul 21, 2014, 3:48:03 AM7/21/14
to seleniu...@googlegroups.com
Hi Samal, 

So in your case it is taking one window into Set..that means u need to put some time after clicking on some button which is present in Parent WIndow like...

driver.findElement(
By.xpath("html/body/div[1]/div[2]/div/div[2]/div/div[2]/form/div[13]/div[2]/span/ul/li/a"))
.click();

Thread.sleep(5000);

Try this...surely it should work...

Reply me if it doesnt works




--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/Oy35RcXdaGo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks
K.Sreenivasulu

Biswajit Samal

unread,
Jul 21, 2014, 5:06:50 AM7/21/14
to seleniu...@googlegroups.com
Hi Seenu,

Thanks again for guiding me, but I am still on the same platform . till not I am not sure about navigating form parent to child is a window, or a frame.  I went through the HTML but not able to recognize it properly. but by following example avail online, i believe it is a browser window on which I am unable to pass the control.

When the child window open, then execution stops if I do some action on child window then only the execution continue and get out put in console which I have sent you earlier.
Reply all
Reply to author
Forward
0 new messages