AutoMater AutoMater - 1 year ago 224
Java Question

switch tabs using Selenium WebDriver with Java

Using Selenium WebDriver with JAVA ,
I am trying to automate a functionality where I have to open a new tab do some operations there and come back to previous tab (Parent).
I used switch handle but its not working.
And one strange thing the two tabs are having same window handle due to which i am not able to switch between tabs.

However when I am trying with different Firefox windows it works, but for tab its not working.

Please help me how can i switch tabs.
OR how can I switch tabs without using window handle as window handle is same of both tabs in my case.

(I have observed that when you open different tabs in same window , window handle remains same.)

Answer Source
    ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());

This code perfectly worked for me. Try it out. You always need to switch your driver to new tab, before you want to do something on new tab.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download