问题
When I run my code it's showing below error - Electron application
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'DESKTOP-GN8LLQU', ip: '192.168.1.20', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: driver.version: ChromeDriver
My Code:
ChromeOptions opt = new ChromeOptions();
// path of your Electron Application
opt.setBinary("D:\\FOS\\fiber-optic-system-electron\\release\\angular-electron 0.1.0.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", opt);
capabilities.setBrowserName("chrome");
System.setProperty("webdriver.chrome.driver", "E:\\chromedriver_win32 (6)\\chromedriver.exe");
WebDriver driver = new ChromeDriver(capabilities);
回答1:
I have been experiencing the error DevToolsActivePort file doesn't exist myself and in my case the error was correct and the root cause was the electron app itself.
Since v2.39 Chrome's web driver (chromedriver.exe) by default looks for a file named DevToolsActivePort and when found reads it to obtain the port number of devtools that is currently running in chrome (and in your case the Chrome instance that the electron app "angular-electron 0.1.0.exe" is running).
When you create a ChromeDriver in Selenium and include the --remote-debugging-port=0 argument, or otherwise do not include this argument at all, then chromedriver will send --remote-debugging-port=0 in the command line to your electron app (ie. angular-electron 0.1.0.exe). If your electon app passes this argument onto the Chrome app running inside it then the DevToolsActivePort file is created, chromedriver can read it and gain the port of devtools, and automation is successful. However if your electron app does not pass this argument to Chrome then the DevToolsActivePort file is never created and your chromedriver times out looking for it and fails.
You have a couple of options for a solution:
- Have the developers of the electron app ensure the "--remote-debugging-port" argument is passed onto Chrome.
- Automate your own solution for creating the "DevToolsActivePort" file.
In my case I went with option 2. Here's how you can test this option manually. If you run an application like SysInternal's Tcpview (https://docs.microsoft.com/en-us/sysinternals/downloads/tcpview) before your electron app then Tcpview will show you the ports that your electron app is listening on. One of these ports will be the Chrome's devtools port. Note this down. Now go into your %temp% folder in Windows as this is the default location for the temporary folder containing the DevToolsActivePort file that chromedriver is looking for. In this folder look for the folders prefixed with scoped_dir. By default chromedriver will create one these each time you run it. To guarantee you access the correct folder it's best to set this directory name yourself beforehand in chromedriver using the --user-data-dir argument before running it. Go into this folder and create a new file named DevToolsActivePort and enter the port number on the first line, press Enter (newline), and then any number on the second line. Save the file and close. If you complete this entire process manually within 60 seconds the running chromedriver will read that file, get the port of Chrome's devtools, connect to it and continue.
I have developed an AutoIT script that does the above process automatically and I include this in my own automation runs and works every time.
Hope this helps.
回答2:
This error message...
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'DESKTOP-GN8LLQU', ip: '192.168.1.20', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: driver.version: ChromeDriver
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
- Possibly you are using the latest chromedriver=77.0
- Possibly you are using_chrome= 77.0_
- Your Selenium Client version is 3.6.0 of 2017-09-27T15:28:36.4Z which is almost 2 years older.
- Your JDK version is 11.0.2.
So there is a clear mismatch between the Selenium Client v3.6.0 , ChromeDriver v77.0 and the Chrome Browser v77.0
Solution
Ensure that:
- Selenium is upgraded to current levels Version 3.141.59.
- ChromeDriver is updated to current ChromeDriver v77.0 level.
- Chrome is updated to current Chrome Version 77.0 level. (as per ChromeDriver v77.0 release notes)
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
- Take a System Reboot.
- Execute your
@Test
as non-root user. - Always invoke
driver.quit()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
Note: As per Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11 it may be a better idea to downgrade to Java 8
Outro
- WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
来源:https://stackoverflow.com/questions/58500512/showing-error-unknown-error-devtoolsactiveport-file-doesnt-exist-its-elec