selenium+python 写web自动化脚本,在Safari浏览器上遇到这个问题:
selenium.common.exceptions.ElementNotVisibleException: Message: An element command could not be completed because the element is not visible on the page.
https://github.com/SeleniumHQ/selenium/issues/5355
也就是链接显示的这个问题,有一个回答如下:
You can find details at https://bugs.webkit.org/show_bug.cgi?id=174710. This bug has been fixed, but Apple have yet to fix this in SafariDriver. This has been reported to Apple under bug report number 33459305.
是苹果浏览器的问题,目前在开发版已经解决,但是还没发布
那么怎么解决Safari浏览器的点击问题呢?
解决方法如下:
通过调用js的方法进行操作
- execute_script(script, *args)
Example:
ele = browser.find_element_by_xpath('//*[@id="1$Menu"]/li')
browser.execute_script('arguments[0].click();', ele)
可正常执行