【问题标题】:Selenium Python: Neither Element Click or .send_keys work on this webpageSelenium Python:Element Click 或 .send_keys 在此网页上均不起作用
【发布时间】:2020-08-11 04:04:47
【问题描述】:

this 网页上,我无法弄清楚如何在搜索框中输入文本或从下拉菜单中选择给定状态。这似乎很简单,因为我在其他网站上也这样做过,但我无法弄清楚。

尝试 1(从下拉列表中选择):

driver = webdriver.Chrome()
driver.get("https://orderz.sheetz.com/#/main/location/search")

driver.find_element_by_xpath('//*[@id="state-search"]/select/option[2]').click()

尝试 2(在搜索中输入文本):

driver = webdriver.Chrome()
driver.get("https://orderz.sheetz.com/#/main/location/search")

driver.find_element_by_xpath('//*[@id="storeSearchForm"]/div/div/input').send_keys("pa", Keys.ENTER)

尝试 1 的错误消息:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="state-search"]/select/option[2]"}

尝试 2 的错误消息:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="storeSearchForm"]/div/div/input"}

任何建议都非常感谢!

【问题讨论】:

  • 网页没有为我打开。你能检查一下那个 webelement 是否在 iframe 中吗?
  • sheetz.com,然后点击右上角“Find A Sheetz”

标签: python python-3.x selenium xpath selenium-chromedriver


【解决方案1】:

你可以尝试使用 JavaScript 执行器来点击网页元素吗?

请参考链接:https://dzone.com/articles/perform-actions-using-javascript-in-python-seleniu

【讨论】:

  • @jack,你还在面对同一个拦截器吗?
  • 不幸的是,它仍然不起作用。你能让它工作吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-05
  • 2016-04-12
  • 2020-06-02
  • 1970-01-01
  • 2021-02-01
  • 2022-12-18
  • 2017-06-14
相关资源
最近更新 更多