【发布时间】:2021-03-28 13:02:26
【问题描述】:
我在 Ubuntu 上成功运行了一个 python3 selenium 脚本,当我尝试无头运行时,它在元素不可交互时出错:
Traceback (most recent call last):
File "file.py", line 143, in <module>
driver.find_element_by_xpath('//*[@id="ctl00_MainContent_MyReportViewer_ctl04_ctl00"]').click()
File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jobs/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: headless chrome=87.0.4280.88
我看过一篇文章,说这可能是 chrome 与对象交互的方式不同,所以我在 Firefox 上也尝试过,结果相同。
我要更改的唯一行是:
chrome_options.add_argument("--headless")
【问题讨论】:
标签: python-3.x selenium xpath css-selectors webdriverwait