简体   繁体   中英

Invalid port. Exiting..Exception in thread "main" org.openqa.selenium.WebDriverException: Driver server process died prematurely ChromeDriver Selenium

Installation details

I have installed

  • java version : 1.8
  • selenium jar version : 3.141.59,
  • chrome browser version : 84.0.4147.89.

I want to launch the google in chrome browser using selenium web-driver test case. But I am not able to launch due the above attached issue.

错误快照

Please help me to fix the issue.

It seems that you are facing a problem with the driver configuration, it can be the configuration code, driver versions or Windows configuration or even the Browser itself. Here is a tutorial step by step on how to configure the basics properly:

Here is how to configure the code side and also the last version of chrome :

if you are working on a maven project I want to throw a suggestion: use: bonigarcia webdrivermanager library . Just add this to your pom

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.2.0</version>
    </dependency>

and the configuration is much more simpler.

...
WebDriver driver= driverClass.getDeclaredConstructor().newInstance();
WebDriverUtils util = new WebDriverUtils(driver);
driver.get("google.com");
...

And that is it, With this you will need to worry much less about configuration of the driver. it automatically imports the driver and configures it for you. Here is a tutorial in case you wanna try.

This error message...

Invalid port. Exiting...
Exception in thread "main" org.openqa.selenium.WebDriverException: Driver server process died prematurely.

...implies that the ChromeDriver server process was unable to bind to the assigned free port within your system.

As per the discussion Getting Invalid port error and Invalid port. Exiting...

"Invalid port. Exiting..." occurs when the port assigned to chromedriver is less than 0 or greater than 65535.


Debugging steps

Perform the following steps one by one to address the issue:

  • Execute netstat command through CLI to see if you have reached limit of possible open connections or check if there is another application running on the port used by ChromeDriver .
  • Check your firewall settings, there is a good chance that firewall configuration may be blocking the communication.
  • Upgrade ChromeDriver to current ChromeDriver v2.84 level.
  • Upgrade Chrome to current Chrome v84.0 levels. ( as per ChromeDriver v84.0 release notes )
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client .
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • ( WindowsOS only ) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite .
  • ( LinuxOS only ) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite .
  • Take a System Reboot to free up the used ports.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Alternative

As an alternative you can force the WebDriver variant ie ChromeDriver to start on a specific port eg 65535 as follows:

  • Code Block:

     System.setProperty("webdriver.chrome.driver","C:\\WebDrivers\\chromedriver.exe"); WebDriver driver= new ChromeDriver(new ChromeDriverService.Builder().usingPort(65535).build()); driver.get("https://www.google.com/");
  • Console Output:

     Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 65535 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully. Jul 20, 2020 7:36:17 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C

References

You can find a couple of relevant detailed discussions in:

You need to update your exe version https://chromedriver.chromium.org/downloads in this link you can download driver exe and set in path

Can you kill chrome exe and refresh and rerun ( note open cmd and paste this line and enter taskkill /im chromedriver.exe /f and rerun project

Please import import org.openqa.selenium.chrome.ChromeDriver;

In my case it was that ChromeDriver version wss not compatible with Chrome Browser version. Make sure you are using the right versions.

Here you can find more information if you don't know which versions are compatible--> Which ChromeDriver version is compatible with which Chrome Browser version?

For the above problem, I understood what was root cause.

Mistake: I have done mistake of deleting system variable path while adding the JAVA_HOME in the environmental variable. Hence I do suggest,Please don't delete any system path while adding or editing the system variable.

Second thing: I have reset the window-10 operating system to get the exact system path,which supported me to execute the selenium test cases.

Because of setting incorrect system path in the environmental variable,My system operating system was unable to reach to specific browser driver's. which implies, that the Chrome-driver server process was unable to bind to the assigned free port within our system.

conclusion :The above issue got resolved for me, By resetting windows-10 OS. Install eclipse editor,JDK, selenium jar files,different drivers with respective browser and execute the test case.

I hope it will help to some one, who is facing same issue. Thanks..

I faced the same error and then I followed the steps shared at Timon/Web.com.

Step 1 — Find chromedriver binary path To find chromedriver binary path, run the following command in the terminal:

which chromedriver

The output should be similar to:

terminal output /usr/local/bin/chromedriver

Step 2 — Lift the quarantine for the chromedriver binary Now you need to tell Mac OS to trust this binary by lifting the quarantine. Do this by the following terminal command:

xattr -d com.apple.quarantine /usr/local/bin/chromedriver

Now, rerun your test or script, and it should be able to run chromedriver without the error.

Below is the link which I referred:

https://timonweb.com/misc/fixing-error-chromedriver-cannot-be-opened-because-the-developer-cannot-be-verified-unable-to-launch-the-chrome-browser-on-mac-os/

Its working fine for me. May be it will help you as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM