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.)
This will work for the MacOS for Firefox and Chrome:
This method helps in switching between multiple windows. The restricting problem with this method is that it can only be used so many times until the required window is reached. Hope it helps.
Since the
driver.window_handles
is not in order , a better solution is this.I had a problem recently, the link was opened in a new tab, but selenium focused still on the initial tab.
I'm using Chromedriver and the only way to focus on a tab was for me to use
switch_to_window()
.Here's the Python code:
So the tip is to find out the name of the window handle you need, they are stored as list in
Simple Answer which worked for me:
Please see below:
Hope this is helpful!