【问题标题】:Unable to access the element using Selenium , Python and ChromeDriver无法使用 Selenium 、 Python 和 ChromeDriver 访问元素
【发布时间】:2021-01-28 17:50:44
【问题描述】:

Unable to Access the password by name 从 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)

【问题讨论】:

  • passwordid 里面有什么

标签: python selenium-webdriver xpath css-selectors webdriverwait


【解决方案1】:

您需要为element_to_be_clickable() 诱导WebDriverWait 而不是presence_of_element_located(),您可以使用以下Locator Strategies 之一:

  • 使用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
    

【讨论】:

  • WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "password"))).click() 文件 "/usr/local/lib/python3.7/site -packages/selenium/webdriver/support/wait.py",第 80 行,直到引发 TimeoutException(消息、屏幕、堆栈跟踪)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2011-12-28
  • 2019-10-25
相关资源
最近更新 更多