How to use headless chrome with selenium to scroll AND click elements? - selenium-chromedriver

Adding the command line --headless to my chrome driver resulted with few problems in some of my automation testcases.
Some elements where not interactable until I added the argument --window-size=1920,1080, but on the other hand, adding this argument resulted with a new problem with testcases that uses JQuery's scrolling function (e.g $('#element').scrollBy(...)).
To the intractability problem I found a solution here, and to the scrolling problem I found a solution here. But what should I do with --window-size which solves one and creates an other problem? and why does it affect scrolling at all?
======
Scrolling Error Info:
no error is thrown but scrolling simply does not work.
======
Not interactable Error Info:
TimeoutError: An error occurred while running .click() command on <Element [name=#openFiltersView]>: (Session info: headless chrome=87.0.4280.88), (Driver info: chromedriver=87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280#{#355}),platform=Windows NT 10.0.18363 x86_64); element not interactable
{"status":-1,"state":"","value":{"message":"element not interactable","error":[" (Session info: headless chrome=87.0.4280.88)"," (Driver info: chromedriver=87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280#{#355}),platform=Windows NT 10.0.18363 x86_64)"]},"errorStatus":11,"error":"element not interactable","httpStatusCode":200}

Related

finding Element causing chrome driver instance to crash

First the Environment:
Node JS 16.15.0
Web Driver io v7 (wdio)
wdio/cucumber framework
end to end testing of a website
-obviously using cucumber and feature files
using a test configuration file similar to wdio's
using wdio-chromedriver-service v7.2.6 and npm chromedriver package version ^107 to produce a browser to hit
my browser : chrome v107.0.5304.62
The Question:
an element cannot be found by webDriver as I expect, but the command causes the instance to crash
I am searching for an element that no longer appears on the page (it is a spinner element that shows the page is loading)
I call
if(await this.spinner.isDisplayed())
and then the test run hangs, the debugger tells me the command
INFO webdriver: COMMAND findElement("css selector", "i.fa-spinner")
is running and then nothing else, finally the renderer times out
WARN chromedriver: [SEVERE]: Timed out receiving message from renderer: 600.000
DEBUG webdriver: request failed due to response error: timeout
and the chrome instance crashes shortly later
I am unsure why this behavior is happening, is something wrong with my wdio configuration? or with my chrome driver?
What I have tried
I understand that
browser.setTimeout exists but
I am sure it is not set in my config anywhere.
I have done a global search (using vscode for all development) for browser.setTimeout (no results).
I have manually set browser.setTimeout({ 'implicit': 0 }) (no success).
I have also tried directly hitting a chrome driver instance by manually downloading a chrome driver exe that matched my browser version v107.0.5304.62 and removing the 'services: ['chromedriver']'
from my test config file
when this happens something very interesting occurs, I can keep running after searching for the element that broke the run before, but we dont get very far and the command still causes issues. Chrome driver is throwing errors like
error: 'no such element',
[0-0] message: 'no such element: Unable to locate element: {"method":"css selector","selector":"i.fa-spinner"}\n' +
[0-0] ' (Session info: chrome=107.0.5304.87)'
The browser closes shortly afterwards without progressing through the rest of the tests.
I find it interesting that the version that chrome driver says it is running is 107.0.5304.87 since the version of chromedriver I downloaded clearly says it is v107.0.5304.62 and my chrome version clearly states it is also v107.0.5304.62 .
though theoretically using v107.0.5304.87 shouldnt be an issue according to this
since the 107.0.5304 part matches across the board
I could use some assistance.
We had the same issue this days, seems there is a bug introduced in Chrome 106; try to change config or downgrade Chrome on the machine to use Chrome 105 as with this version is working.

Selenium Webdriver tests not running on Chrome headless due to "unable to connect to renderer" error

Chrome version running: 67.0.3396.79
Chromedriver version: 2.40.0 (https://www.npmjs.com/package/chromedriver)
When running the selenium webdriver tests in Chrome headless mode, getting error:
SessionNotCreatedError: session not created exception
from disconnected: unable to connect to renderer
(Session info: headless chrome=67.0.3396.79)
(Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 3.13.0-74-generic x86_64)
at Object.checkLegacyResponse (/home/jenkins/workspace/1-sunrise-e2e-tests-dev/node_modules/selenium-webdriver/lib/error.js:546:15)
Goodness me! Looks like the issue was with '--remote-debugging-port=9222', which I added to the headless Chrome options, removing that, fixed it.

"Cannot get automation extension" error on headless chrome with Selenium (Ubuntu)

I've installed latest Google Chrome 57.0.2987.110, on my Ubuntu server (16.04).
I'm using canopy (which is F# wrapper for Selenium).
I put latest chromedriver in the same folder as my binary, version: 2.28.455506 (and I set the correct path to driver).
I'm starting chrome with --headless argument, like this:
let chromeOpts = ChromeOptions ()
chromeOpts.AddArgument "--headless"
chromeOpts.AddArgument "--disable-gpu"
chromeOpts.AddArgument "start-maximized"
start <| ChromeWithOptions chromeOpts
As soon as it's starts I get this error:
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: content shell=)
(Driver info: chromedriver=2.28.455506 (18f6627e265f442aeec9b6661a49fe819aeeea1f),platform=Linux 4.4.0-64-generic x86_64)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError (OpenQA.Selenium.Remote.Response errorResponse) [0x000d5] in <2096f357ed27440a8e98c8a8dd645cdd>:0
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute (System.String driverCommandToExecute, System.Collections.Generic.Dictionary`2[TKey,TValue] parameters) [0x00046] in <2096f357ed27440a8e98c8a8dd645cdd>:0
at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute (System.String driverCommandToExecute, System.Collections.Generic.Dictionary 2[TKey,TValue] parameters) [0x00000] in <2096f357ed27440a8e98c8a8dd645cdd>:0
at OpenQA.Selenium.Remote.RemoteWindow.set_Size (System.Drawing.Size value) [0x00067] in <2096f357ed27440a8e98c8a8dd645cdd>:0
at canopy.core.pin (canopy.types+direction direction) [0x0002f] in <58c4b5b9d8107025a7450383b9b5c458>:0
at canopy.core.start (canopy.types+BrowserStartMode b) [0x0050c] in <58c4b5b9d8107025a7450383b9b5c458>:0
It's seems that it fails to set window size.
Is it proper way to launch headless Chrome? I read somewhere that newest version has headless feature.
As I'm using newest version of both Google Chrome and chromedriver I think it shouldn't be a version mismatch.
Also it's working fine on ma local Windows 10 machine with same version of chromedrive (just for windows).
Running with command (and without headless argument):
DISPLAY=:1 xvfb-run mono myapp.exe
Seems to work. I think this resolves my issue.
I leave it here for others looking for a way tu run headless chrome and having same problem.
This solution comes from: http://coderscoffeehouse.com/tech/2017/01/17/headless-front-end-testing-on-linux-using-fsharp.html
There's an open Chromium issue on this topic. It states:
Headless mode doesn't currently support extensions, and it's not clear
whether we can support them easily -- although we are doing some
initial feasibility analysis.
As suggested by #mateuszlewko, the X Virtual Framebuffer (XVFB) can be used as a Linux workaround.

My robot framework test does not work with chrome

I have written some test suites with robot framework using RIDE. As browser I have used Firefox and all test passed without any problem. But I have now to use Chrome as reference browser. But chrome isn't working. So I have done a very simple test case:
Open Browser http://google.com ${BROWSER}
If I enter "ff" as my ${BROWSER} variable I get a Firefox window with the google website displayed within it.
When I change the ${BROWSER} variable to chrome, I get a browser window which is black.
I get the following error in the log file:
WebDriverException: Message: session not created exception
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64)
My configuration is:
Robot Framework 3.0
RIDE 1.5.2.1
Selenium2Library 1.7.4
Python 2.7.12
wx 2.8.12.1
Google Chrome 55
Chromedriver 2.27

Selenium - Uncaught WebDriverError: chrome not reachable

Currently I'm using the follow stack:
1. Selenium Webdriver 3.0.1 (NodeJS API)
2. Mocha
3. Chromedriver 2.25.3
Often when I run my tests in Codeship (continuous integration) I get this error:
Uncaught WebDriverError: chrome not reachable
(Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.2.0-42-generic x86_64)
Note: This never happened running locally, only occurs when my tests start in codeship, and it's an intermittent error (sometimes it happens, sometimes not)
Screenshot error:
Any ideia how solve this?
Does codeship have chrome installed on their test server?
I'm guessing not. It might be better to run this against phantomjs (headless browser) instead for CI purposes.