当我在无头模式 chrome 浏览器中运行测试脚本时,元素链接不可见,无法执行linkElement.click()
。在头部模式下一切正常。所有其他信息都在堆栈跟踪中。请问有谁知道怎么办?
堆栈跟踪:
发生错误:消息:元素不可见
(会话信息:无头 chrome=60.0.3112.90)
(驱动程序信息:chromedriver=2.31.488763(092de99f48a300323ecf8c2a4e2e7cab51de5ba8),平台=Windows NT 6.1.7601 SP1 x86_64)
回溯(最近一次通话):
文件“C:\nik-x.py”,第 148 行,在 main
func(nik)
文件“C:\lib\support.py”,第 121 行,在 wrapper
raise ret
文件“C:\lib\support.py ",第 108 行,在 newFunc
res[0] = func(*args, **kwargs)
文件“C:\testcases\nik-1003.py”,第 37 行,在 testcase
i.click()
文件“C:\ Python36\lib\site-packages\selenium\webdriver\remote\webelement.py",第 7 行
7,点击
self._execute(Command.CLICK_ELEMENT)
文件“C:\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py”,第 4
93 行,在 _execute 中
返回 self._parent.execute(command, params)
文件“C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py”,第 25 行
6,在执行
self.error_handler.check_response(response)
文件“C:\Python36\lib\site-packages\ selenium\webdriver\remote\errorhandler.py",第
194 行,在 check_response 中
引发 exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: headless chrome=60.0.3112.90)
(驱动程序信息:chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),平台=Windows NT 6.1.7601 SP1 x86_64)
这是我的一段代码:
icons = nik.elementLeftmenuSportIcons()
for i in icons[:-1]:
try:
i.click()
来自测试页面的 HTML: <a href="#" class="default b_futbal gaPageEventElement" data-ga-cat="Sporty" data-ga-action="futbal">
<span class="left-menu-only-large-res">Futbal</span>
</a>