Im trying to build a project maven for automationg testiong the scenarios working fine when i excute them on local but when i try to build the job I got this error
i already added the chromedriver, the build is on a vm Linux i added the chromedriver for Lunix too
I downloaded the last version of chrome driver.
Thanks
It may be caused by following reasons,
In linux/vm we need to provide executable/higher permission on chrome driver.
chmod 777 chromedriver
if you connecting to remote driver, we need to do port connectivity between machines.
Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.
from selenium import webdriver
d = webdriver.Chrome('/home/PycharmProjects/chromedriver')
d.get('https://www.google.nl/')
i get the following error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)
i have the latest chrome version and chromedriver installed
EDIT:
After trying #b0sss solution i am getting the following error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)
Try to download HERE and use this latest chrome driver version:
https://sites.google.com/chromium.org/driver/
Try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the Chrome browser is not installed at the default location within your system.
The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Solution
In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Python Solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe" #chrome binary location specified here
options.add_argument("--start-maximized") #open Browser in maximized mode
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
Java Solution:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); //chrome binary location specified here
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.com/");
hope this helps someone. this worked for me on Ubuntu 18.10
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()
I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome-stable is
no longer running, so ChromeDriver is assuming that Chrome has crashed.)
When I tried running chrome locally /usr/bin/google-chrome-stable, error message
Running as root without --no-sandbox is not supported
I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)
I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')
For RobotFramework
I solved it! using --no-sandbox
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument test-type
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
Instead of
Open Browser about:blank headlesschrome
Open Browser about:blank chrome
Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.
If you close all tabs and run again, the error should clear up.
in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:
opts.set_headless(True)
A simple solution that no one else has said but worked for me was not running without sudo or not as root.
The solutions that every body provide here is good for Clear the face of the issue but
All you need to solve this problem is that You have to run The App on non-root user
on linux.
According to this post
https://github.com/paralelo14/google_explorer/issues/2#issuecomment-246476321
I had the same problem but it was solved just by reinstalling chrome again with the commands below:
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb
This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.
Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.
It solved the issue I was having; not elegantly but it works.
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
try:
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
print("\nChrome crashed on launch:")
print(e)
print("Trying again in 10 seconds..")
sleep(10)
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
print("Success!\n")
except Exception as e:
raise Exception(e)
I came across this error on linux environment. If not using headless then you will need
from sys import platform
if platform != 'win32':
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Faced with this issue trying to run/debug Python Selenium script inside WSL2 using Pycharm debugger.
First solution was to use --headless mode, but I prefer to have Chrome GUI during the debug process.
In the system terminal outside Pycharm debugger Chrome GUI worked nice with DISPLAY env variable set this way (followed guide here):
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
Unfortunately ~/.bashrc is not running in Pycharm during the debug, export is not working.
The way I've got Chrome GUI worked from Pycharm debugger: run echo $DISPLAY in WSL2, paste ip (you've got something similar to this) 172.18.144.1:0 into Pycharm Debug Configuration > Environment Variables:
Just do not run the script as the root user (in my case).
i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.
i faced the same problem but i solved it by moving the chromedriver to this path
'/opt/google/chrome/'
and this code works correctly
from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')
In my case, chrome was broken. following two lines fixed the issue,
apt -y update; apt -y upgrade; apt -y dist-upgrade
apt --fix-broken install
Fixed it buy killing all the chrome processeses running in the remote server before running my script.
That may explain why some answers that recommend you run your script as root works.
$ pkill -9 chrome
$ ./my_script.py
Maybe when you where developing in local, you used options.headless=False in order to see what is the browser doing but you forgot to change it to True in the vm.
For me, the root issue was that the google-chrome/chromedriver version were not compatible with the Selenium version.
Seleniumn and Chrome were working fine until a few days ago and I started getting this missing DevToolsActivePort issue. After trying all sorts of solutions on this thread, it finally occurred to me that the Chrome version might not be compatible with the Selenium version.
Versions at the time of the initial error:
# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77
I then downgraded Chrome and ChromeDriver to 109.0.5414.74 but still faced the same error. I checked the versions on a different machine and saw that this combo worked:
# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16
However, I wasn't able to find a download for Google Chrome V80. This comment had a download to V97 so that's the version I went with. There might be higher versions of Google Chrome that do work but after spending so many days fixing this, I was eager to move onto something else.
sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable
wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin
After that, my Selenium calls were able to work again. The final version combo:
# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71
Make sure that both the chromedriver and google-chrome executable have execute permissions
sudo chmod -x "/usr/bin/chromedriver"
sudo chmod -x "/usr/bin/google-chrome"
I have a WebDriver based Java testsuite, which I try to execute with Jenkins.
Project is imported and build was successful.
During execution of test I get following:
Running TestRunner
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#2437c6dc
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console
output
It seems doesn't found binary, but it is located in the given path.
Failed tests: runBeforeTest(TestRunner): Failed to connect to binary
FirefoxBinary(/home/user1/Desktop/firefox/firefox-bin) on port 7055;
process output follows: (..)
Before execution I started a X server.
Xvfb :19 -screen 0 1024x768x16 &
export DISPLAY=:19
firefox &
Versions:
Ubuntu 16.04.3
Selenium 2.53.1
Firefox 55.0
Jenkins 2.60.3
This is likely to be a version mismatch between Selenium and Firefox.
According to a comment on one of their GitHub issues, Selenium 2.53.1 is known to work well with Firefox 47.0.1.
https://github.com/SeleniumHQ/selenium/issues/2527
To keep using Firefox 55, you need to use a higher version of Selenium (if it's already supported).
My environment:
linux ubuntu
selenium-html-runner-3.4.0.jar
selenium-java-3.4.0
selenium-server-standalone-3.4.0.jar
to build I do:
javac -cp "/usr/share/java/junit.jar:/home/me/ushare/hobo/selenium/selenium-html-runner-3.4.0.jar:." TestHobo2.java
to run selenium-server:
java -jar selenium-server-standalone-3.4.0.jar
to run the test I do:
java junit.textui.TestRunner TestHobo2
and I get:
java.lang.RuntimeException: Could not start Selenium session:
at
com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:114)
at
com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:139)
at
com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:108)
at
com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:113)
at TestHobo2.setUp(TestHobo2.java:10) at
com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:289)
Caused by: com.thoughtworks.selenium.SeleniumException:
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:111)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:105)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:277)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:239)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:105)
... 15 more
Here is my test case:
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class TestHobo2 extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.example.com/", "*chrome");
}
public void testGetLink() throws Exception {
selenium.type("name=p_loc", "groove");
selenium.click("css=input[type=\"Submit\"]");
selenium.waitForPageToLoad("30000");
}
}
Edit 2017/07/20 More info:
I am using Firefox version 52.0.2 (64-bit).
Should I be getting the following after the build?
Note: TestHobod2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
geckodriver -v
1500554646753 geckodriver INFO geckodriver 0.18.0
1500554646753 webdriver::httpapi DEBUG Creating routes
1500554646764 geckodriver ERROR Address in use (os error 98)
Are you sure that you have properly defined on which ip address and port is selenium running? Run your selenium server and put http://127.0.0.1:4444/wd/hub/ link into your browser. Try to create new session manually (click on create session and select browser, see image below), new browser blank window should appear. If this is working correctly than selenium server is ok. Then there can be problem with connection between server and your runner.
screen of selenium hub with create session option
Do you have correctly setup selenium driver? For example I'm using
new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"),DesiredCapabilities.firefox())
EDIT1: Show example of setUp method which create instance of RemoteDriver, create new browser session and fill url.
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), DesiredCapabilities.firefox());
driver.manage().window().maximize()//maximaze window as possible
driver.get("www.google.com"); //navigate to google, i.e. fill url into opened session
Looking at the codebase, and trying to map your shared test code, seems to suggest that you will end up invoking a Firefox browser. The underlying implementation in Selenium has ensured that this will cause your test code to resort to perhaps using firefox.
Can you please ensure that you have made geckodriver downloaded and made available in your PATH variable ?
If that doesn't fix the problem (which could mostly be due to mismatch between the firefox version that you have in your desktop and the geckodriver version ), you can try switching to using Google Chrome.
You can switch to google chrome by
Changing : setUp("http://www.example.com/", "*chrome");
To : setUp("http://www.example.com/", "*googlechrome");
And see if that spins off the browser (For google chrome you would need to ensure you have chromedriver downloaded and made available in your local machine)
I just got some trouble when I move my automation test script using Java & Selenium, from my local env (OSX) to my server env (Ubuntu 14 without GUI of course).
So this is the problem.
I try to run my automation test using this command java -jar MyAutomation.jar 3 1 1
3 1 1 is just an application arguments, so there is nothing to do with it in our case.
But after I ran that command, I got my java selenium try to open chrome browser via chromedriver. But unfortunately, this error message has appeared :
PAC support disabled because there is no system implementation
And another error message comes by, here we go :
Exception in thread "main" org.openqa.selenium.WebDriverException:
unknown error: Chrome failed to start: exited abnormally (Driver
info: chromedriver=2.10.267518,platform=Linux 3.13.0-36-generic
x86_64) (WARNING: The server did not provide any stacktrace
information) Command duration or timeout: 60.54 seconds
and of course, I do not know for sure how come it is. But when I try to run in my local env with GUI (in OSX env), it runs without any problem, everything is run well. So in my short analysis, this error comes when I try to run chrome browser in non GUI.
So I try to make some changes in my linux server env. I try to install Xvfb so that my OS works as if there is a GUI control over it.
I start the Xvfb by using this bash script.
I re-run my automation script, and still got the problem. For short insight, I include some snippet here of how I my automation script is.
public void execute(String username, String password){
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = new ChromeDriver();
System.out.println("Try pull all etalase");
ServiceCommonNav.login(driver, username, password);
ServiceCommonNav.moveTo(driver, "https://www.somewebsitetoscrap.com");
Gson gson = new Gson();
List<Etalase> etalases = pullEtalaseList(driver);
SaveEtalaseRequest request = new SaveEtalaseRequest();
request.setEtalases(etalases);
SaveEtalaseWS ws = new SaveEtalaseWS();
ws.call(request);
String json = gson.toJson(etalases);
System.out.println(json);
}
If, if i strongly required to run my scraper over this Xvfb, what is the proper way to achieve that? (So that my opened chrome browser always runs over Xvfb and work as if the browser is headless).
What the step, and what code should I modified to achieve that.
Very beg for your help, I just got stucked for this problem for more than a week. Geez.... :(
Thanks in advance...