简体   繁体   English

Selenium 无法定位元素

[英]Selenium is unable to locate element

I'm trying to automate this website, but I can't make selenium find elements with xpath.我正在尝试自动化此网站,但我无法使用 xpath 使 selenium 查找元素。

This is the html:这是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.我试过完整的 xpath,但它不起作用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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