使用driver.find_element_by_xpath()可以找到按钮,但在此之后我使用click()然后弹出一些错误,如下所示:
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 65, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 385, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: 'Element is not currently visible and so may not be interacted with' ; Stacktrace:
at fxdriver.preconditions.visible (file:///C:/Users/LIANGD~1/AppData/Local/Temp/tmp_hdmf0mu/extensions/fxdriver@googlecode.com/components/command-processor.js:8936:5)
at DelayedCommand.prototype.checkPreconditions_ (file:///C:/Users/LIANGD~1/AppData/Local/Temp/tmp_hdmf0mu/extensions/fxdriver@googlecode.com/components/command-processor.js:11595:1)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/LIANGD~1/AppData/Local/Temp/tmp_hdmf0mu/extensions/fxdriver@googlecode.com/components/command-processor.js:11612:11)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/LIANGD~1/AppData/Local/Temp/tmp_hdmf0mu/extensions/fxdriver@googlecode.com/components/command-processor.js:11617:7)
at DelayedCommand.prototype.execute/< (file:///C:/Users/LIANGD~1/AppData/Local/Temp/tmp_hdmf0mu/extensions/fxdriver@googlecode.com/components/command-processor.js:11559:5)
为什么会发生这种情况?
答案 0 :(得分:0)
错误消息告诉您确切的原因:
元素目前不可见,因此可能无法与
进行交互
Selenium只允许你与可见元素进行交互,假设如果它不可见,那么用户就无法与它进行交互,如果用户无法与之交互,那么selenium也不会。