我正在尝试运行此代码以启动chrome驱动程序。 我的Google Chrome浏览器使用的是77版,而我的Chrome驱动程序也使用的是77版。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class test1
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "hey/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
但是我得到
Invalid port. Exiting...
أكتوبر ٠٤, ٢٠١٩ ٤:٤٣:٣٧ ص org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:31.527Z'
System info: host: 'DESKTOP-NRP2HUM', ip: '172.20.10.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.4'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at test1.main(test1.java:17)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:٤٦١٣٩/status] to be available after ٢٠٠٠٣ ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
... 9 more
Caused by: java.util.concurrent.TimeoutException
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:204)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 10 more
Process finished with exit code 1
我没有在网上搜索过运气,在这里我也查看了关于stackoverflow的类似主题,但不幸的是没有任何效果。 非常感谢您的帮助。
答案 0 :(得分:0)
尝试使用ChromeDriverService指定空闲端口。在下面的代码中,使用了34533端口。您可以对其进行更改。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
public class test1
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "hey/chromedriver.exe");
WebDriver driver= new ChromeDriver(new ChromeDriverService.Builder().usingPort(34533).build());
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}
}