Edgedriver not in PATH when executing selenium scripts on Linux VM - linux

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)

Related

DevToolsActivePort file doesn't exist Selenium testing

I am trying to execute python selenium tests on a linux vm. I am using webdriver-manager to automatically select the right edge driver. However, this is what my error looks like:
Exception has occurred: 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.)
Whats the reason behind this error? How can I fix it? Thanks for your help!
Code:
import os
import time
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
base_url = "http://localhost:5000/"
driver.get(base_url)

Running Test in Docker using Chrome and Chromedriver in Python

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?

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.

selenium.common.exceptions.SessionNotCreatedException: Message: session not created from tab crashed using ChromeDriver Chrome Selenium Python

I am having this error apparently when trying to access a url that the script requests, does not have a specific. I don't understand exactly why this error, but I want to treat it so as not to abort the script when it occurs.
This make duplicate, but not solution my problem: How to avoid the error: selenium.common.exceptions.SessionNotCreatedException: Message: session not created from tab crashed
code:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--incognito')
chrome_options.add_argument('--headless')
driver = webdriver.Chrome("/driver/chromedriver", options=chrome_options)
Error:
Traceback (most recent call last):
File "scripts/page11.py", line 15, in <module>
driver = webdriver.Chrome(BASE_WEB_DRIVER, options=chrome_options)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from tab crashed
(Session info: headless chrome=78.0.3904.108)
Chrome: Google Chrome 78.0.3904.108 and driver: ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904#{#877}) are compatible.
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from tab crashed
(Session info: headless chrome=78.0.3904.108)
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Analysis and Solution
There are diverse solution to this issue. However as per UnknownError: session deleted because of page crash from tab crashed this issue can be solved by either of the following solutions:
Add the following chrome_options:
chrome_options.add_argument('--no-sandbox')
Another option to make it work would be to add the chrome_options as --disable-dev-shm-usage. This will force Chrome to use the /tmp directory instead. This may slow down the execution though since disk will be used instead of memory.
chrome_options.add_argument('--disable-dev-shm-usage')
So effectively, you code block will be:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(executable_path='/driver/chromedriver', options=chrome_options)
from tab crashed
from tab crashed was WIP(Work In Progress) with the Chromium Team for quite some time now which relates to Linux attempting to always use /dev/shm for non-executable memory. Here are the references :
Linux: Chrome/Chromium SIGBUS/Aw, Snap! on small /dev/shm
Chrome crashes/fails to load when /dev/shm is too small, and location can't be overridden
As per Comment61#Issue 736452 the fix seems to be have landed with Chrome v65.0.3299.6
Reference
You can find a detailed discussion in unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed with ChromeDriver Selenium
I had the same issue and I spent more than 4 hours by trying so many things like I used addArguements(), tried another version of chrome driver but nothing worked
After that I just restart my system and the problem was resolved. There is some memory issue.

Resources