gpt4 book ai didi

java - 实例化 RemoteWebDriver 时出错

转载 作者:行者123 更新时间:2023-11-30 12:07:25 25 4
gpt4 key购买 nike

我正在尝试通过以下代码使用 RemoteWebDriver 启动 chrome 浏览器。

File file = new File("E:\\S\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
//System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
//capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9898/"),capability);

我收到以下错误:

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

我检查过端口 9898 是否打开。我在 C:\Windows\System32\drivers\etc\hosts

的主机中添加了 localhost

更新:我可以看到另外两个异常(exception)。

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:9515 [/127.0.0.1] failed: Connection refused.

Caused by: java.net.ConnectException: Connection refused:

最佳答案

我看到您的 chrome 版本适合您的 chromedriver。我不确定应该/可以使用哪个端口,但您可以尝试以下选项:

WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9898"), capability);

WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), capability);

在本地运行测试

您可以使用new ChromeDriver(capabilities);

远程运行测试

您需要安装 selenium 服务器。也可以安装在本地机器上。您可以在这里找到它:https://www.seleniumhq.org/download/安装并运行后,您可以使用 RemoteWebDriver 连接到它。

您可以在 selenium 文档中获得更多信息 https://docs.seleniumhq.org/docs/03_webdriver.jsp#running-standalone-selenium-server-for-use-with-remotedrivers

关于java - 实例化 RemoteWebDriver 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54988679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com