我正在尝试在Java绑定下将chrome驱动程序与Selenium一起使用。我遵循以下指示:ChromeDriver指示
所以我运行ChromeDriver.exe,将其放在我的代码中WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.chrome());,然后出现此错误:
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) ... ... ...
尝试您的代码时出现编译错误 The constructor RemoteWebDriver(String, DesiredCapabilities) is undefined
The constructor RemoteWebDriver(String, DesiredCapabilities) is undefined
对于Java,您可以尝试类似的方法,
System.setProperty("webdriver.chrome.driver","Drive:"+File.separator+"chromedriver.exe"); driver = new ChromeDriver(); driver.get(url);