简体   繁体   中英

Selenium is unable to locate element

I'm trying to automate this website, but I can't make selenium find elements with xpath.

This is the html:

<input aria-describedby="6076de12_1595321303833_errors" class="form-control" value="" name="6076de12_1595321303833" placeholder="" type="text" data-export-field="" title="Nombre y Apellidos / Name and Last Name">

This is my code:

# driver = webdriver.Chrome(executable_path='../drivers/chromedriver')
driver.get('website')
time.sleep(3)
search = driver.find_element_by_xpath('//*[@id="6076de12_1595321303833"]/input').send_keys(Nom)

I've tried with full xpath, but it doesn't work.

What should I do?

Thanks a lot!

This name is propably not a constant value but the class seems to be so you can try this :

 search = driver.find_element_by_xpath(“//input[@class=‘form-control’]”)

If it won't work:

 search = driver.find_element_by_xpath(“//input[@title=‘Nombre y Apellidos / Name and Last Name’]”)

Induce some waits after getting the page so the page loads and you don't miss the element. Grab an input with class form-control and send keys.

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control"))).send_keys("AAA")

Import

from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM