Running Test in Docker using Chrome and Chromedriver in Python - python-3.x

I am trying to run some tests in Docker using chromedriver and chrome in Python.
chrome_options = Options()
chrome_options.add_argument('--headless')
However, I used the add_argument('--headless') I have a returning error : Engine not supported, Your version currently configured does not support this"
But, if I do not used the add_argument('--headless'), I received this error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Any tip?

Related

SessionNotCreatedException: Could not start a new session. Response code 500 using ChromeDriver on Apache Tomcat/10.0.23 on a remote server

I'm running a java webapp in Apache Tomcat/10.0.23 on a remote server which implements selenium chromedriver. Whenever I create the webdriver it returns a HTTP Status 500 – Internal Server Error.
Google-chrome location:
/usr/bin/google-chrome /usr/share/man/man1/google-chrome.1.gz
Google-chrome version:
110.0.5481.77
Chromedriver location:
/usr/bin/chromedriver
Chromedriver version:
110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481#{#839})
Selenium
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.8.0</version>
</dependency>
Error:
<body>
<h1>HTTP Status 500 – Internal Server Error</h1>
<hr class="line" />
<p><b>Type</b> Exception Report</p>
<p><b>Message</b> Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start:
crashed.</p>
<p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.
</p>
<p><b>Exception</b></p>
<pre>org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'ip-xxxxxxxxxx2', ip: '127.0.0.1'
Build info: version: '4.8.0', revision: '267030adea'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.0-21-cloud-amd64', java.version: '11.0.15.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless=new, --disable-dev-shm-usage, --no-sandbox], extensions: []}, pageLoadStrategy: eager}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless=new, --disable-dev-shm-usage, --no-sandbox], extensions: []}, pageLoadStrategy: eager}}]
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:82)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:71)
com.fourdcontrols.servlets.TestServlet.doGet(TestServlet.java:29)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:668)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
</pre>
<p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p>
<hr class="line" />
<h3>Apache Tomcat/10.0.23</h3>
</body>
Logs:
Starting ChromeDriver 110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481#{#839}) on port 3125
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Thumb rule
A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
References
You can find a couple of relevant detailed discussion and documentation in:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
Chrome doesn't start or crashes immediately

Edgedriver not in PATH when executing selenium scripts on Linux VM

I want to test a localhost app with a selenium script that is executed on a linux VM. No matter whether I try with a manually added webdriver or the webdriver-manager it says "selenium.common.exceptions.WebDriverException: Message: 'msedgedriver' executable needs to be in PATH."
Any ideas how to fix that? Thanks for your help!
Of course, I skimmed stackoverflow for similiar questions - and there are plenty, but it still doesnt work here. The other error I receive from time to time is: selenium.common.exceptions.WebDriverException: Message: unknown error: Microsoft Edge failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from msedge location /usr/bin/microsoft-edge is no longer running, so msedgedriver is assuming that msedge has crashed.)
import os
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager
os.environ['PATH'] += r"msedgedriver.exe"
# #Suppress irrelevant error messages
options = webdriver.EdgeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Edge(options=options)
#driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager(options=options).install()))
base_url = "http://localhost:5000/"
driver.get(base_url)

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally." (Driver info: chromedriver=97) using Selenium Python

I installed the most up-to-date version of Chrome, then I verified that the execution_path of the webdriver.Chrome was deprecated, I put the Selenium Service lib and still I can't connect, what could be happening in the code?
def create_selenium_driver():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
prefs = {"download.default_directory" : "/tmp/chrome_downloads/", 'profile.default_content_setting_values.automatic_downloads': 1}
chrome_options.add_experimental_option("prefs",prefs)
chrome_driver = "/tmp/chromedriver/chromedriver"
s = Service(chrome_driver)
driver = webdriver.Chrome(service=s, options=chrome_options)
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
This error message...
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally." (Driver info: chromedriver=97)
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
The up to date google-chrome version is chrome=96.0.4664.45
But you are using chromedriver=97
Release Notes of chromedriver=97.0 clearly mentions the following :
Supports Chrome version 97
So there is a clear mismatch between chromedriver=91.0 and the chrome=96.0.4664.45
Solution
Ensure that:
ChromeDriver is updated to current ChromeDriver v96.0 level.
Chrome is updated to current chrome=96.0.4664.45 (as per chrome=96.0.4664.45 release notes).

error chrome as crashed when trying to launch selenium chromedriver unix centos7 [duplicate]

This question already has answers here:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
(44 answers)
Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
(22 answers)
Closed 2 years ago.
I have spent hours on this error. tried all the given solutions and still have the following error :
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I have a linux/centos7 - I am using ssh putty to connect the serveur.
I have
google-chrome --version
Google Chrome 85.0.4183.102
chromedriver -v
ChromeDriver 85.0.4183.87
Here is my code
#!/usr/bin/python3.6
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url='https://www.google.com'
option = webdriver.ChromeOptions()
option.add_argument('–-no-sandbox')
option.add_argument('–-headless')
option.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=option)
driver.get(url)
print(driver.page_source)
driver.quit()
I have also tried with
#!/usr/bin/python3.6
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Chrome()
url='https://www.google.com'
driver.get(url)
print(driver.page_source)
driver.quit()
and still have the same error. Through ssh I have tried as root and non-root user but still the same..
As information, when doing
google-chrome --no-sandbox : gives :
[4463:4463:0919/160950.452059:ERROR:browser_main_loop.cc(1417)] Unable to open X display.
[root#ns344379 mail_from_any_webpage]# [0919/160950.501241:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
[0919/160950.501399:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
and I add that I had installed google-chrome successfully but I had an error message while installation : "Redirecting to /bin/systemctl start atd.service
Failed to start atd.service: Unit not found." (I am under plesk)
Running transaction
Installation : google-chrome-stable-85.0.4183.102-1.x86_64 1/1
Redirecting to /bin/systemctl start atd.service
Failed to start atd.service: Unit not found.
Vérification : google-chrome-stable-85.0.4183.102-1.x86_64 1/1
Installé :
google-chrome-stable.x86_64 0:85.0.4183.102-1
Terminé !

Is there a way to use selenium in combination with the Opera GX Browser?

I'm trying to get the current page url on my Opera GX browser, but I can't find if there is a way to do it. I thought selenium might work, but when I run my code, it gives me this in the command prompt:
[12252:21468:0914/190450.397:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
The output error in the python IDE is this one:
selenium.common.exceptions.WebDriverException: Message: unknown error: Opera failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from opera location C:/Users/remis/AppData/Local/Programs/Opera GX/launcher.exe is no longer running, so OperaDriver is assuming that Opera has crashed.)
(Driver info: operadriver=84.0.4147.89 (19abfe7bcba9318a0b2a6bc6634a67fc834aa592-refs/branch-heads/4147#{#852}),platform=Windows NT 10.0.18363 x86_64)
Here is my code:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
import time
options = Options()
options.binary_location = "C:/Users/remis/AppData/Local/Programs/Opera GX/launcher.exe"
driver = webdriver.Opera(executable_path="C:/Users/remis/PycharmProjects/FormationChecker/operadriver_win64/operadriver.exe", options = options)
print(driver.current_url)
time.sleep(1)
I'm very new to selenium and this is just a very simple test. I hope someone can help me with this.

Resources