I have used below code, but it throws an error saying "Cannot focus on element". Please help.
String selectAll = Keys.chord(Keys.ALT,"T");
driver.findElement(By.tagName("html")).sendKeys(selectAll);
I have used below code, but it throws an error saying "Cannot focus on element". Please help.
String selectAll = Keys.chord(Keys.ALT,"T");
driver.findElement(By.tagName("html")).sendKeys(selectAll);
You can send ShortcutKeys like
Alt + Tab
to driver without using element by using Actions.However your goal was to switch to the window/tab.In Selenium both window and tab are same.
I've provided you two solutions which is self explanatory from the name of the functions
You can open another tab using:
and switch to tabs by using:
The best way to switch tabs would be to use switchTo(), if you know the new window name:
Otherwise get a list of the open windows and switch using that:
So you can iterate over the open windows until you find the one you need.