Abhishek Gupta
Abhishek Gupta

Reputation: 161

How to send text to the Email field using Selenium and Python

enter image description here

Hi tried something like it was working before

driver.find_element_by_xpath("//*[@id="loginForm"]/div/div[1]/input").send_keys("[email protected]")

but now it gives error

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="inputs"]//input[@name="email"]"}

Upvotes: 1

Views: 3836

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193108

To send a character sequence to the Email field you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solution:

  • CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']"))).send_keys("[email protected]")
    
  • XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='email']"))).send_keys("[email protected]")
    

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

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

You can try with name :

driver.find_element_by_name("email").send_keys("[email protected]")  

in case you want to introduce webDriverWait :

wait = WebDriverWait(driver,10)

wait.until(EC.element_to_be_clickable((By.NAME, 'email'))).send_keys("[email protected]")  

Note that you will have to imports these :

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

UPDATE1:

You are in iframe , you will have to switch the focus of your web driver to default content and then you can interact with it:

driver.switch_to.default_content()

wait.until(EC.element_to_be_clickable((By.NAME, 'email'))).send_keys("[email protected]")

Upvotes: 2

Related Questions