无法在Selenium远程WebDriver中启动Chrome浏览器



我是Selenium的新手。我正在尝试使用远程web驱动程序启动Chrome。下面是我正在使用的环境。

Windows : Windows 10 Enterprise
Java Version : 9.0.4
Selenium Standalone Jar : 3.5.3
IDE : Eclipse

在我的本地机器上启动集线器和节点服务器,如下所示在一个CMD会话-

java -jar selenium-server-standalone-3.5.3.jar -role hub
22:10:41.391 INFO - Selenium build info: version: '3.5.3', revision: 'a88d25fe6b'
22:10:41.391 INFO - Launching Selenium Grid hub
2022-05-25 22:10:43.322:INFO::main: Logging initialized @2152ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:10:43.332 INFO - Will listen on 4444
2022-05-25 22:10:43.365:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2022-05-25 22:10:43.381:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
2022-05-25 22:10:43.381:INFO:osjs.session:main: No SessionScavenger set, using defaults
2022-05-25 22:10:43.382:INFO:osjs.session:main: Scavenging every 600000ms
2022-05-25 22:10:43.387:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@4d0d9fe7{/,null,AVAILABLE}
2022-05-25 22:10:43.399:INFO:osjs.AbstractConnector:main: Started ServerConnector@1500b2f3{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2022-05-25 22:10:43.400:INFO:osjs.Server:main: Started @2230ms
22:10:43.400 INFO - Nodes should register to http://********:4444/grid/register/
22:10:43.401 INFO - Selenium Grid hub is up and running
22:10:44.300 INFO - Registered a node http://******:5555
22:10:54.537 INFO - Registered a node http://********:5555
22:10:54.537 WARN - Cleaning up stale test sessions on the unregistered node http://********:5555

在另一个CMD会话中,我像下面这样-

java -jar -Dwebdriver.chrome.driver="C:********chromedriver.exe" selenium-server-standalone-3.5.3.jar -role node -hub http://localhost:4444
22:10:51.312 INFO - Selenium build info: version: '3.5.3', revision: 'a88d25fe6b'
22:10:51.313 INFO - Launching a Selenium Grid node
2022-05-25 22:10:53.750:INFO::main: Logging initialized @2658ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:10:53.773 INFO - Driver class not found: com.opera.core.systems.OperaDriver
22:10:53.783 INFO - Driver provider class org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN10
22:10:53.798 INFO - Using the passthrough mode handler
2022-05-25 22:10:53.811:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2022-05-25 22:10:53.824:WARN:osjs.SecurityHandler:main: ServletContext@o.s.j.s.ServletContextHandler@4ed5eb72{/,null,STARTING} has uncovered http methods for path: /
2022-05-25 22:10:53.826:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@4ed5eb72{/,null,AVAILABLE}
2022-05-25 22:10:53.837:INFO:osjs.AbstractConnector:main: Started ServerConnector@e19bb76{HTTP/1.1,[http/1.1]}{0.0.0.0:5555}
2022-05-25 22:10:53.837:INFO:osjs.Server:main: Started @2745ms
22:10:53.837 INFO - Selenium Grid node is up and ready to register to the hub
22:10:53.845 INFO - Starting auto registration thread. Will try to register every 5000 ms.
22:10:53.845 INFO - Registering the node to the hub: http://localhost:4444/grid/register
22:10:54.537 INFO - The node is registered to the hub and ready to use

我有Chrome的代码如下-


public class ChromeFactory extends DriverFactory{

String mcWebUrl;
public ChromeFactory(String mcURL) {
mcWebUrl = mcURL;
initBrowser();
}

@Override
protected void initBrowser() {
try {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("chrome");
URL remoteUrl = new URL("http://*******:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(cap);
driver.get(mcWebUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}

我得到下面红色的消息,这就是所有的浏览器不启动-

May 25, 2022 10:23:25 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing
WebDriver driver = new RemoteWebDriver(cap);

您缺少参数URL

正确的调用方法是:

URL remoteUrl = new URL("http://*******:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(*remoteUrl* , cap);

相关内容

  • 没有找到相关文章

最新更新