我正在尝试在java绑定下使用带有Selenium的chrome驱动程序。我按照以下说明操作: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)
...
...
...
答案 0 :(得分:2)
我在尝试代码时遇到了编译错误The constructor RemoteWebDriver(String, DesiredCapabilities) is undefined
对于Java,你可以试试这样的东西,
System.setProperty("webdriver.chrome.driver","Drive:"+File.separator+"chromedriver.exe");
driver = new ChromeDriver();
driver.get(url);
答案 1 :(得分:0)
我已经安装了chromedriver throw mac terminal,然后将此代码添加到java类中;它对我有用。
WebDriver driver;
@Test
public void test() throws MalformedURLException {
WebDriver driver = new RemoteWebDriver(new
java.net.URL("http://localhost:9515"),
DesiredCapabilities.chrome());
driver.get("https://www.facebook.com");
driver.findElement(By.name("email")).sendKeys("hello world");
}