How to fix this issue element not interactable Selenium Python

浪子不回头ぞ 提交于 2019-12-23 16:17:32

问题


I have the following line in my script code, where the XPath I got it from Selenium IDE that works fine:

driver.find_element_by_xpath("(//a[contains(@href, '')])[20]").click()

An automation test stops here with this error:

Traceback (most recent call last):
File "Script.py", line 65, in <module>
    driver.find_element_by_xpath("//a[contains(@href, '')])[20]").click()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 6.1.7601 SP1 x86_64)

How to fix this issue?

Thanks for any help.


回答1:


Seeing as you just want to scrape the data, I recommend you use this solution:

element = driver.find_element_by_xpath("(//a[contains(@href, '')])[20]")
driver.execute_script("arguments[0].click();", element)

Which clicks the element via Javascript as opposed to a "natural" click that selenium uses (to try to simulate the user experience).

I answered a similar question here that links to another post on it as well.



来源:https://stackoverflow.com/questions/56194094/how-to-fix-this-issue-element-not-interactable-selenium-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!