I wish to switch between browser tabs for a feature I am testing. However I have not been able to do this. Have tried using the following:
page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
The idea been that when I am on the second tab the above code should bring it back to the first tab. However this is not working.
I also just tried to close the second tab using this:
page.execute_script "window.close();"
but this does do anything, the tab is not closed nor is the overall browser window so appears that it is not doing anything.
Had anybody else had problems like this and how did you figure out a solution? I am using FireFox.
Here's my method for closing new tabs.
def close_new_tabs
window = page.driver.browser.window_handles
if window.size > 1
page.driver.browser.switch_to.window(window.last)
page.driver.browser.close
page.driver.browser.switch_to.window(window.first)
end
end
I call this method anytime a new tab may need to be closed.
I was able to switch between tabs using the following
browser.switch_to.window browser.window_handles.last
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With