![](/img/trans.png)
[英]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.