Selenium Python: Expected "handle" to be a string, got [object Undefined] undefined

Viewed 2245

I use Firefox. I click a button but the page opens as a new tab and selenium stays focused on the original page with the button. I'm trying to switch and get the new url.

time.sleep(4)
second_driver.switch_to.window(second_driver.window_handles[1])
print(second_driver.current_url)

I get:

selenium.common.exceptions.InvalidArgumentException: Message: Expected "handle" to be a string, got [object Undefined] undefined

I also tried the following but it didn't have an effect. I still got the url of the old page.

second_driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
1 Answers

This was a Geckodriver bug. It was resolved on the 0.27.0 version release: https://github.com/mozilla/geckodriver/releases

I have used to experience the same issue with the 0.24.0 version and then I have upgraded the Geckodriver to this version, and then the issue stopped happening.

However, I recommend using always the latest version of Geckodriver. I have checked with the 0.29.0 version and the bug is also gone.

Related