【问题标题】:selenium phantomJS states 'element is not visible' but works fine in firefoxselenium phantomJS 状态“元素不可见”但在 Firefox 中工作正常
【发布时间】:2016-01-22 23:16:46
【问题描述】:

我正在尝试将邮政编码输入商店网站,当我使用 webdriver.firefox() 但不适用于 PhantomJS 时,这可以正常工作。相反,我得到一个错误:

NoSuchElementException: Message: {"errorMessage":"Unable to find element with id 'SL-map-search'"

这是我用来生成请求的相当简单的代码。仅使用 set_window_size 是因为其他类似问题表明这可能会解决问题(它没有)。

driver = webdriver.PhantomJS()
# get address
driver.set_window_size(1920,1080)
driver.get("http://www.lowes.com/StoreLocatorDisplayView")

# select zipcode
element = driver.find_element(By.ID, 'SL-map-search')
element.send_keys(zipcode)
driver.find_element(By.ID, 'SL-map-search-submit').click()

任何帮助将不胜感激!

【问题讨论】:

  • 你在 Chrome 中试过了吗? PhantomJS 使用与 Chrome 相同的 JS 引擎。您使用的是哪个版本的 PhantomJS?还是您使用的是 GhostDriver?另外,这是什么语言;也许添加标签。
  • 我使用的是 phantomjs v 2.0.0。我不认为我正在使用ghostdriver。我会检查铬!
  • 它适用于 chrome,所以我猜它不适用于 PhantomJS - 关于我应该如何进行的任何建议?
  • 添加等待。从一个愚蠢的Thread.sleep() 开始(仍然不知道您使用的是什么语言!),看看这是否会改变任何东西。如果是,则开始使用适当的 Selenium 等待。

标签: python selenium webdriver phantomjs


【解决方案1】:

Wait for the element 出席:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, "SL-map-search"))
)
element.send_keys(zipcode)

【讨论】:

    【解决方案2】:

    当我升级到 El Capitan 时,该错误已修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多