我正在尝试查找搜索栏并使用以下代码向其发送输入文本:
searchBar = browser.find_element_by_xpath('//*[@id="u_e_2"]/input[2]')
searchBar.send_keys("my-text-here")
browser.implicitly_wait(10)
searchBar.send_keys(Keys.ENTER)
但是得到以下错误:
File ".\get-quotes.py", line 46, in <module>
searchBar = browser.find_element_by_xpath('//*[@id="u_e_2"]/input[2]')
File "D:\ahmed-quotes\quote-env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "D:\ahmed-quotes\quote-env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "D:\ahmed-quotes\quote-env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "D:\ahmed-quotes\quote-env\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="u_e_2"]/input[2]"}
(Session info: chrome=81.0.4044.138)
知道我是在Chrome浏览器中检查元素时复制xpath的。
我的代码有什么问题
Facebook大量混淆了它的HTML以阻止你做这种事情。这包括在每页生成随机ID、标记和其他属性
相关问题 更多 >
编程相关推荐