Lucas
Lucas

Reputation: 599

NoSuchElementException: Message: no such element: Unable to locate element error filling user name using Selenium and Python

I wish to enter username and password on the following site

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()
browser.get('https://baud.teamwork.com/launchpad/login?continue=%2Fcrm')
username = driver.find_element_by_id("loginemail")
username.send_keys("YourUsername")

I tried changing

driver.find_element_by_name

and still doesn´t work

I get the following error:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"loginemail"}

Upvotes: 1

Views: 679

Answers (3)

Justin Lambert
Justin Lambert

Reputation: 978

Even if your locators correct selenium could not identify , because you need to wait for that element then only you can do some actions 

use this line before username locator line.(but thread sleep does not use nowadays because of time consuming ,if we use thread sleep (3000) our execution script line will delay for 3 sec )

    browser = webdriver.Chrome()
browser.get('https://baud.teamwork.com/launchpad/login?continue=%2Fcrm')
**Thread.sleep(3000);**
username = driver.find_element_by_id("loginemail")
username.send_keys("YourUsername")



Best way is please use Webdriver wait in selenium

Upvotes: 1

user13944733
user13944733

Reputation:

Try changing this:

username = driver.find_element_by_id("loginemail")

into this:

username = browser.find_element_by_id("loginemail")

Or the entire code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()
browser.get('https://baud.teamwork.com/launchpad/login?continue=%2Fcrm')
username = browser.find_element_by_id("loginemail")
username.send_keys("YourUsername")

Upvotes: 1

undetected Selenium
undetected Selenium

Reputation: 193338

To send a character sequence within the Email address filed you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://baud.teamwork.com/launchpad/login?continue=%2Fcrm")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#loginemail"))).send_keys("[email protected]")
    
  • Using XPATH:

    driver.get("https://baud.teamwork.com/launchpad/login?continue=%2Fcrm")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='loginemail']"))).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
    
  • Browser Snapshot:

baud


References

You can find a couple of relevant discussions on NoSuchElementException in:

Upvotes: 2

Related Questions