'Why is Python Selenium switching to other code without waiting?

its my code

driver = uc.Chrome(use_subprocess=True)
wait = WebDriverWait(driver, 20)
url = 'https://accounts.google.com/ServiceLogin?service=accountsettings&continue=https://myaccount.google.com%3Futm_source%3Daccount-marketing-page%26utm_medium%3Dgo-to-account-button'
driver.get(url)


wait.until(EC.visibility_of_element_located((By.NAME, 'identifier'))).send_keys(email)
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.NAME, 'password'))).send_keys(password)


WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//header/div[2]/div[3]/div[1]/div[1]/div[1]/div[1]/a[1]")))

driver.execute_script('''window.open("www.google.com","_blank");''') 
driver.switch_to.window(driver.window_handles[1])

google logs in but then gives this error

driver.switch_to.window(driver.window_handles[1])
IndexError: list index out of range

I guess after waiting it goes to the next line without running javascript

I need your help, Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source