1

I'm trying to use chrome driver with Selenium under java bindings. I follow these instructions : ChromeDriver Instructions

So I run ChromeDriver.exe, put this in my code WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.chrome()); and I get this error :

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)

How to get chrome driver to work ?

Edit : With the other method :

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

I get these errors :

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)
...
...
...
Wicelo
  • 2,358
  • 2
  • 28
  • 44
  • 1
    Hmm, Why you use RemoteWebDriver?? Why not use [this](https://sites.google.com/a/chromium.org/chromedriver/getting-started) approach?! If you seemply need use chrome driver in your tests, it's not necessary to use RemoteWebDriver. Moreover, seems that selenium server hasnot been started before you start using RemoteWebDriver. – Andrey Egorov Sep 02 '14 at 05:35

3 Answers3

2

I got the compilation error, while trying your code The constructor RemoteWebDriver(String, DesiredCapabilities) is undefined

For Java, you could try something like this,

  System.setProperty("webdriver.chrome.driver","Drive:"+File.separator+"chromedriver.exe");
  driver = new ChromeDriver();
  driver.get(url);
Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57
  • It is a replacement for // and works for all OS. look at this http://stackoverflow.com/questions/2417485/file-separator-vs-slash-in-paths – Vignesh Paramasivam Sep 02 '14 at 06:07
  • well yeah I saw that you were right it launches the server and a window of google chrome but then it still throw errors :`java.lang.NullPointerException at com.example.tests.Scrapjv.testScrapjv(Scrapjv.java:54) ` – Wicelo Sep 02 '14 at 06:09
  • Post your entire method, since opening the browser doesn't throw this error – Vignesh Paramasivam Sep 02 '14 at 06:11
  • well even when I comment out the entire method I still get the error, the program crashes as soon as the chrome window pop out. – Wicelo Sep 02 '14 at 06:18
  • Can you post the code? I can't tell the problem what it is without it. Since opening the browser doesn't throw any errors – Vignesh Paramasivam Sep 02 '14 at 06:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60432/discussion-between-wicelo-and-vignesh-paramasivam). – Wicelo Sep 02 '14 at 06:46
  • Hi Vignesh, I am trying to use your answer but I am getting error as "setProperty - cannot resolve symbol setProperty" am I missing anything by the way I am using IntelliJ 2016.1.2 community edition. – user790049 May 18 '16 at 06:54
  • 1
    @user790049 This should help http://stackoverflow.com/questions/5905896/intellij-inspection-gives-cannot-resolve-symbol-but-still-compiles-code – Vignesh Paramasivam May 18 '16 at 11:04
1

I have install chromedriver throw mac terminal, then add this code to java class; it work for me.

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");
}
Reksmey
  • 11
  • 3
0

You could try:

WebDriver driver = new RemoteWebDriver(new java.net.URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome());
Bubletan
  • 3,833
  • 6
  • 25
  • 33
Karan
  • 443
  • 5
  • 14
  • It's always a good idea to describe *why* this would solve the issue. This will give the asker an additional clues what went wrong. – Artjom B. May 02 '15 at 17:36