【问题标题】:send_keys is failing with phantomJSsend_keys 使用 phantomJS 失败
【发布时间】:2018-07-03 18:44:35
【问题描述】:

Selenium send_keys() 方法在使用 phantomJS 时不起作用,即使它在不使用 phantomJS 的情况下也能正常工作。

这是我正在使用的代码:

password = wait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@id='password']")))
password.send_keys("pass1")

【问题讨论】:

  • 有什么异常>
  • 能否请您添加脚本的下几行? (在password.send_keys("pass1")之后)
  • @demouser123 这是例外行:--> 文件“E:\Selenium\gen_Login.py”,第 35 行,在 Login_func wait(self.driver, 10).until(EC.element_to_be_clickable ((By.XPATH, "//input[@class='form-control' and @id='password']"))).send_keys("pass1") 文件 "C:\Users\AppData\Local\Programs \Python\Python36-32\lib\site-packages\selenium\webdriver\support\wait.py",第 80 行,直到引发 TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: 消息:跨度>

标签: python-3.x selenium xpath phantomjs


【解决方案1】:

看来你已经很接近了。根据文档,您需要将内置的WebDriverWait() 方法与expected_conditions 结合使用作为element_to_be_clickable(),您可以使用以下任一解决方案:

  • CSS_SELECTOR:

    WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control#password"))).send_keys("pass1")
    
  • XPATH:

    WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='form-control' and @id='password']"))).send_keys("pass1")
    

【讨论】:

  • 同样的错误:/文件“E:\Selenium\gen_Login.py”,第 35 行,在 Login_func 等待(self.driver,10).until(EC.element_to_be_clickable((By.XPATH,“ //input[@class='form-control' and @id='password']"))).send_keys("pass1") File "C:\Users\AppData\Local\Programs\Python\Python36-32\ lib\site-packages\selenium\webdriver\support\wait.py",第 80 行,直到引发 TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
  • 我正在使用 webdriverwait 作为等待,就像在代码开头一样。从 selenium.webdriver.support.ui 导入 WebDriverWait 作为等待
猜你喜欢
  • 1970-01-01
  • 2015-05-05
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多