问题
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.
回答1:
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;
回答2:
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.
回答3:
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()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
Alternative
As an alternative you can force the WebDriver variant i.e. ChromeDriver to start on a specific port e.g. 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:
- Invalid port. Exiting… org.openqa.selenium.os.OsProcess checkForError while launching chrome using selenium
- org.openqa.selenium.os.OsProcess checkForError and org.apache.commons.exec.ExecuteException: Process exited with an error with Selenium ChromeDriver
- “OsProcess checkForError : CreateProcess error=193, %1 is not a valid Win32 application” while starting Internet Explorer through Java and Selenium
回答4:
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?
回答5:
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..
来源:https://stackoverflow.com/questions/62993623/invalid-port-exiting-exception-in-thread-main-org-openqa-selenium-webdrivere