WebDriverException: unknown error: DevToolsActivePort file doesn't exist - selenium

I have an issue when trying a simple test with selenium avec chromedriver. I get the error org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
This has been reported a couple of time on stackoveflow, i've read near all the answers without success at this time.
I'm using a corporate managed computer without admin rights, using chrome 86.0.4240 with same version of chromedriver, selenium-standalone-server 3.9.1.
The code used is below, with the trace of different tries according to different stackoverflow topics found.
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\" + System.getProperty("user.name") + "\\Downloads\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("127.0.0.1:9000");
options.setCapability("proxy", proxy);
// Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
// https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t/51326137#51326137
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--no-sandbox"); // Bypass OS security model
// All chrome process are previously killed : Get-Process -Name chrome* | Stop-Process
// https://stackoverflow.com/questions/59987080/invalidargumentexception-message-invalid-argument-user-data-directory-is-alre
//options.addArguments("--user-data-dir=C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Local\\Google\\Chrome\\Automation\\");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com"); }
When i run the test, Chrome Open, display the message tell it's controlled by an automated tool, display "data:" in the URL bar and hang. After a couple of seconds (minutes), the script ends with the above error.
I'm runing on a plain windows 10 plateform, with no docker.
I cannot create a new chrome profile, so i take care to close all chrome process before starting the test.
Any help will be greatly appreciated.

Related

Jenkins fails to run chrome but work fine in Headless[Reference Checked] [duplicate]

This question already has answers here:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
(44 answers)
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
(15 answers)
Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd
(2 answers)
Closed 2 years ago.
If I am running my testng xml locally it works fine in both headless or without however, when I am running it with jenkins it is giving me error in case of not headless
if (Utility.fetchConfigPropertyValue("browserName", config_Property_File_Path).toString()
.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "../ams-common/Drivers/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.setBinary("/usr/bin/google-chrome-stable");
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("disable-extensions"); // disabling extensions
options.addArguments("disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("no-sandbox"); // Bypass OS security model
driver = new ChromeDriver(options);
}
Error on Jenkins
org.openqa.selenium.WebDriverException:
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-stable is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Kindly note I have checked related question but did not resolve my issue.

Even if I run headless, I get an "unknown error: cannot find Chrome binary" error

I'm trying to run Selenium tests in the headless mode in my Jenkins build.
Here is the part of the code where I configure the Chromedriver (yup, many options hahaha):
WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--window-size=1920x1080");
chromeOptions.addArguments("start-maximised");
chromeOptions.addArguments("enable-automation");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-infobars");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--disable-browser-side-navigation");
chromeOptions.addArguments("--disable-gpu");
driver = new ChromeDriver(chromeOptions); // I get the error at this line
Since I run in headless mode, I expect Jenkins not to go find a Chrome binary. But... it does.
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
[... nothing relevant...]
Driver info: driver.version: ChromeDriver
Any idea of what I can do?
Thanks so much in advance

Selenium Chrome Driver - Exception when trying headless option

I am trying to use chrome but I need it to be hidden from the user.
So I tried to use "headless" with ChromeOptions
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C://temp//1.14.12_0.crx"));
options.addArguments("disable-infobars");
options.addArguments("headless");
but then I crashed with the following exception:
[1524948093.974][WARNING]: chrome quit unexpectedly, leaving behind temporary directories for debugging:
[1524948093.974][SEVERE]: Port leaked: 12545
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: failed to wait for extension background page to load: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
from unknown error: page could not be found: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_6
I made some searching and found out that it might be related to the fact that I also load an ad blocker extension, so I temporarily commented the extension loading and the chrome was loaded HIDDEN.
But I still need this extension to work for me when chrome is hidden.
Is there any solution?
Chrome Version - 66
Chrome Driver version - 2.37
Thanks!
So, this one made the trick:
options.addArguments("load-extension=.//resources//1.14.12_0.crx");
instead of
options.addExtensions(new File(".//resources//1.14.12_0.crx"));
Enjoy!

Unable to find a matching set of capabilities with selenium 3.8.1 and gecko driver 0.19.0

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Webdriver {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");
//WebDriver driver = new ChromeDriver();
driver.get("https://maps.mapmyindia.com");
Thread.sleep(2000);
driver.findElement(By.id("auto")).sendKeys("TCS");
Thread.sleep(2000);
driver.findElement(By.id("auto_geo")).click();
When i run this code on eclipse luna there is an error: Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
new FirefoxDriver(DesiredCapabilities caps);
is deprecated, use
FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette", false);
WebDriver webDriver = new FirefoxDriver(options);
and you are good to go
Another possible cause is the outdated Firefox version.
I upgraded the version and it works fine!
I could open the browser only setting options.setCapability("marionette", true);, then in the open window I upgraded through the "About Firefox" dialog. Then you have to remove the line about marionette.
Probably the one I had was only going to work with marionette while we are trying to use it with geckodriver, which has a different protocol. Anyone who knows more than me can confirm or deny!
SessionNotCreatedException
SessionNotCreatedException extends WebDriverException and is a RuntimeException which indicates that a session could not be created.
Possible Causes :
The possible causes of a new session not getting created are as follows :
Compatibility issues between JDK, Selenium, WebDriver and Web Browser versions.
Accessing the same port number by GeckoDriver or Marionette by the new session which previous session have't released yet.
Lack of access to CPU
Lack of Physical Memory
Lack of Swap Memory
Lack of Disc Cache
Lack of Network Bandwidth
Presence of OS chores within the system.
Code Block :
I don't see any coding issue in your code block as such.
Solution :
The simple solution would be as follows :
Always use the latest released version of JDK (Java SE 9.0.1), Selenium-Java client (v3.8.1), WebDriver variant (GeckoDriver v0.19.1) and Web Browser (Firefox Quantum Browser).
If the base version of the Web Browser is too old consider uninstalling the Browser through Revo Uninstaller and install a recent released GA version of Firefox Browser.
Always use quit() in the tearDown() method so that the webdriver and the webclient both are properly destroyed.
Clean the Project Workspace from your IDE before and after executing your Test Suite.
Clear the Browser Cache before and after the execution of your Tests.
Use CCleaner tool regularly to wipe away the OS chores.
Execute your Test.
You should add capabilities for firefox. Please modify your code as follows
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("https://maps.mapmyindia.com");
If your windows is windows_nt then put windows_nt instead of windows

NullPointer Exception In running testCases via Selenium webDriver in Chrome

I am trying to run my test cases on Chrome and I had copied the path in the Properties file,but still console is throwing annoying statements like:
ERROR: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
FAILED CONFIGURATION: #BeforeTest startWebSession
java.lang.NullPointerException
One thing I have found is that the Chrome driver cannot be started from within Eclipse. It must be run from a command prompt. At least on Windows 7 64-bit.
Trying to run it from within Eclipse produces this exception:
Exception in thread "main" java.lang.IllegalStateException: The webdriver.chrome.driver system property defined chromedriver executable does not exist: C:\Windows\System32\chromedriver.exe
This problem only occurs for Chrome. IE and FireFox work fine from within Eclipse.
Download the chrome driver from http://code.google.com/p/chromedriver/downloads/list
Initialize your driver object in the following manner -
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
By doing this the chrome driver works properly.
This is how do I initialize the ChromeDriver:
public RegulationUI() throws Exception{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
}
BTW my test class is named RegulationUI
Try this, it works for me and moreover, I know that this is "multicomputer" solution - our project is in subversion and this way everybody can run it, even if we have differently setup where exactly on disk the "working folder" for IDE is
Please download chromedriver.exe for Google chrome browser
please download IEdriver.exe for Internet explore.
Please And kept these files in a root folder of windows for simplicity. Lets consider your operating systems installed on c:\ (C Driver) create a folder name Selenium on C-Drive and Kept these binary(.exe) files. like c:\selenium
in your Testcase/testScript Write as
//For Chrome Browser:
Webdriver driver = new ChromeDriver();
java.io.File file = new File("c:\\selenium\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
If you are using maven then try to use following in your pom:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
</dependency>
and use it like this for chrome in your setup:
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();