[英]selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element using Selenium ChromeDriver Chrome with Python
[英]Unable to access the element using Selenium , Python and ChromeDriver
无法按名称访问密码从 stackoverflow 答案中尝试了此操作,但仍然无法正常工作
<input type="password" class="required valid" style="font-size: 14px; margin-top: 1em; padding: 0.3em;important: width; 100%:important; border-radius: 3px;" placeholder="password" name="password">
代码试验:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.NAME, passwordId))
).click()
driver.find_element_by_name(passwordId).send_keys(password)
您需要为element_to_be_clickable()
诱导WebDriverWait而不是present_of_element_located () ,并且您可以使用以下任一定位器策略:
使用NAME
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "password"))).click()
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='password'][placeholder='password']"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='password' and @placeholder='password']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.