0

I have a problem with selenium, where it doesn't send the e-mail address properly. the text it sends looks like this: myemailemail.com

the code I'm using looks like this:

EMAIL_LOGIN = driver.find_element_by_id("email")
EMAIL_LOGIN.send_keys(Keys.CONTROL + "a")
EMAIL_LOGIN.send_keys(Keys.DELETE)
EMAIL_LOGIN.send_keys("myemail@email.com")

I tried putting the @ in a variable, still doesn't work. I also tried to put the email itself in a variable, and still nothing.

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281

1 Answers1

-1

Possibly you are trying to invoke send_keys() too early even before the JavaScript enabled webelements have completely rendered.


Solution

You need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using ID:

    EMAIL_LOGIN = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "email")))
    EMAIL_LOGIN.send_keys(Keys.CONTROL + "a")
    EMAIL_LOGIN.send_keys(Keys.DELETE)
    EMAIL_LOGIN.send_keys("myemail@email.com")
    
  • Using CSS_SELECTOR:

    EMAIL_LOGIN = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#email")))
    EMAIL_LOGIN.send_keys(Keys.CONTROL + "a")
    EMAIL_LOGIN.send_keys(Keys.DELETE)
    EMAIL_LOGIN.send_keys("myemail@email.com")
    
  • Using XPATH:

    EMAIL_LOGIN = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']")))
    EMAIL_LOGIN.send_keys(Keys.CONTROL + "a")
    EMAIL_LOGIN.send_keys(Keys.DELETE)
    EMAIL_LOGIN.send_keys("myemail@email.com")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

Alternative

As an alternative you can also use click(), clear() and send_keys() in tandem as follows:

  • Using ID:

    EMAIL_LOGIN = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "email")))
    EMAIL_LOGIN.click()
    EMAIL_LOGIN.clear()
    EMAIL_LOGIN.send_keys("myemail@email.com")
    
  • Using CSS_SELECTOR:

    EMAIL_LOGIN = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#email")))
    EMAIL_LOGIN.click()
    EMAIL_LOGIN.clear()
    EMAIL_LOGIN.send_keys("myemail@email.com")
    
  • Using XPATH:

    EMAIL_LOGIN = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']")))
    EMAIL_LOGIN.click()
    EMAIL_LOGIN.clear()
    EMAIL_LOGIN.send_keys("myemail@email.com")
    
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281