gpt4 book ai didi

java - 带 Selenium 的 Chrome 驱动程序 : "no suitable constructor found for RemoteWebDriver"

转载 作者:行者123 更新时间:2023-11-30 03:46:19 26 4
gpt4 key购买 nike

我正在尝试在 java 绑定(bind)下将 chrome 驱动程序与 Selenium 一起使用。我按照以下说明操作:ChromeDriver Instructions

所以我运行 ChromeDriver.exe,将其放入我的代码中 WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.chrome()); 然后我收到此错误:

Error:(33, 28) java: no suitable constructor found for RemoteWebDriver(java.lang.String,org.openqa.selenium.remote.DesiredCapabilities)
constructor org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor,org.openqa.selenium.Capabilities) is not applicable
(argument mismatch; java.lang.String cannot be converted to org.openqa.selenium.remote.CommandExecutor)
constructor org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriver(java.net.URL,org.openqa.selenium.Capabilities) is not applicable
(argument mismatch; java.lang.String cannot be converted to java.net.URL)

如何让 Chrome 驱动程序工作?

编辑:使用其他方法:

System.setProperty("webdriver.chrome.driver", "PATH\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

我收到这些错误:

java.lang.NullPointerException
at com.example.tests.Scrapjv.testScrapjv(Scrapjv.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
...
...
...

最佳答案

我在尝试您的代码时遇到编译错误构造函数RemoteWebDriver(String, DesiredCapativity)未定义

对于 Java,你可以尝试这样的方法,

  System.setProperty("webdriver.chrome.driver","Drive:"+File.separator+"chromedriver.exe");
driver = new ChromeDriver();
driver.get(url);

关于java - 带 Selenium 的 Chrome 驱动程序 : "no suitable constructor found for RemoteWebDriver",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25616227/

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