When I run test script in headless mode chrome browser, element link is not visible, is not able to do linkElement.click()
. in head mode is everything OK. All other info are in stacktrace.
Anyone knows what to do, please?
StackTrace:
ERROR occurred: Message: element not visible
(Session info: headless chrome=60.0.3112.90)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.1.7601 SP1 x86_64)
Traceback (most recent call last):
File "C:\nik-x.py", line 148, in main
func(nik)
File "C:\lib\support.py", line 121, in wrapper
raise ret
File "C:\lib\support.py", line 108, in newFunc
res[0] = func(*args, **kwargs)
File "C:\testcases\nik-1003.py", line 37, in testcase
i.click()
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 7
7, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 4
93, in _execute
return self._parent.execute(command, params)
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 25
6, in execute
self.error_handler.check_response(response)
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line
194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: headless chrome=60.0.3112.90)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.1.7601 SP1 x86_64)
Here is my piece of code:
icons = nik.elementLeftmenuSportIcons()
for i in icons[:-1]:
try:
i.click()
HTML from testing page: <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>
I think the problem is, that the Element is really not visible in the default viewbox (600x800) of Headless Chrome.
The window size of the Headless Browser must be set as a Argument when starting chrome. I'm using javascript (I think the API looks similar under python):
var Options = require('selenium-webdriver/chrome').Options;
var options = new Options();
options.addArguments('headless');
options.addArguments('disable-gpu');
options.addArguments('window-size=1200,1100');
browser = builder.forBrowser('chrome').setChromeOptions(options).build();
Additional Info
I'm setup up the window size also by webdriver with browser.manage().window().setSize(1200,1100);
But this command is not sufficient in headless chrome. In the non headless variant this is working.