Skip to content
Advertisement

How to send text to the Email field within https://accounts.google.com registration page?

I made proton mail maker script that can go to google sign in and put verification code to proton mail code section.. when I run that, it’s working correctly but it’s not typing google account for signing but he is not typing in the email section I had an error in google account email section

here is my error:

DevTools listening on ws://127.0.0.1:59802/devtools/browser/6bbdae26-bcb4-4789-9e22-0b9e6321ad68
.proton-mail.py:26: DeprecationWarning: use driver.switch_to.default_content instead
  driver.switch_to_default_content()
.proton-mail.py:109: DeprecationWarning: use driver.switch_to.default_content instead
  driver.switch_to_default_content()
Traceback (most recent call last):
  File ".proton-mail.py", line 127, in <module>
    WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")
  File "C:UsersHamza LachiAppDataLocalProgramsPythonPython37-32libsite-packagesseleniumwebdriversupportwait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

python code

driver.execute_script("window.open('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier', 'new window')")
time.sleep(10)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("t")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("s")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("h")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("a")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("m")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("z")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("a")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("m")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("r")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("c")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("h")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")

Advertisement

Answer

You have to switch to the new window before interacting with the elements on the new window.

Use the below line of code to switch to the latest window.

driver.switch_to.window(driver.window_handles[-1])

Once you are done with the actions on the latest window and want to continue with the actions on the parent window (1st window) then switch back using the below code.

driver.switch_to.default_content()

Edit 1:

driver.execute_script("window.open('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier', 'new window')")
# switch to latest window #<=========================
driver.switch_to.window(driver.window_handles[-1])
time.sleep(10)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("t")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("s")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("h")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("a")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("m")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("z")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("a")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("m")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("r")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("c")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("h")
time.sleep(.5)
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='Email']"))).send_keys("i")
# switching back to parent window #<=========================
driver.switch_to.default_content()
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement