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
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

-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
  • 183,867
  • 41
  • 278
  • 352
-1

It's because a non us keyboard.

import pyperclip as pc

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

Email1 = "myemail"
Email2 = "email.com"
AtSign = "@"
pc.copy(AtSign)
AtSign = pc.paste()

EMAIL_LOGIN.send_keys(Email1 + AtSign + Email2)
  • 1
    [Please don't repeat](https://meta.stackexchange.com/q/104227/248627) the [same](https://stackoverflow.com/a/72692324/354577) [answer](https://stackoverflow.com/a/72692204/354577) to multiple questions. – ChrisGPT was on strike Jun 21 '22 at 00:45
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32065499) – dsillman2000 Jun 25 '22 at 19:29