问题描述
在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