Selenium Python:此页面上都不使用Element Click或.send_keys

问题描述

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"}

任何建议,不胜感激!

解决方法

您是否可以尝试使用JavaScript执行器单击Web元素。

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...