title: Selenium Python: Expected "handle" to be a string, got [object Undefined] undefined
body: <p>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.</p>
  <pre><code>time.sleep(4)
  second_driver.switch_to.window(second_driver.window_handles[1])
  print(second_driver.current_url)
  </code></pre>
  <p>I get:</p>
  <pre><code>selenium.common.exceptions.InvalidArgumentException: Message: Expected &quot;handle&quot; to be a string, got [object Undefined] undefined
  </code></pre>
  <p>I also tried the following but it didn't have an effect. I still got the url of the old page.</p>
  <pre><code>second_driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
  </code></pre>