1
package newpackages1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Myclass {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.gecko.driver", "C:\\\\Users\\QGLT01\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("facebook.com/");
        Thread.sleep(5000);
        driver.quit();
    }

}

and it is asking to add the (WebDriver) just before new in the WebDriver driver = new FirefoxDriver();

  • Can you show us the code? – trashpanda Jun 4 '18 at 8:20
  • Your code seems fine to me. What if you add (WebDriver) and start? Will it work? – Alexey R. Jun 4 '18 at 10:22
1

I have also faced the same problem. I just added Typecast and proceeded. The following is working fine.

package com.chamlabs.restfulservices.client.pages;

import org.openqa.selenium.safari.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;

public class LogInPage {

    WebDriver firefoxDriver = (WebDriver) new FirefoxDriver();


}
0

Follow the below code:

RemoteWebDriver driver;
driver = new FirefoxDriver();

This will work

  • it is not working – user33158 Jun 4 '18 at 7:14
  • package newpackages1; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Myclass { public static void main(String[] args) throws java.lang.InterruptedException { System.setProperty("webdriver.gecko.driver", "C:\\\\Users\\QGLT01\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.get("facebook.com/"); Thread.sleep(5000); driver.quit(); } } this is my simple code – user33158 Jun 4 '18 at 7:15
  • What is the error it is showing? – Prasanna venkatesh Jun 4 '18 at 7:22
  • 2
    Why will this work and what is the issue with OP's code? – Alexey R. Jun 4 '18 at 10:34
0

I suspect, what is really going on is not on the new side, but the left side of the instantiation. It could be that the overloaded reference to Webdriver is what is confusing it. You have two name spaces included:

import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;

The last one is obviously more specific than the first, but I suspect that when you are doing this: WebDriver driver = new FirefoxDriver();

That the compiler might be getting confused. Especially since Webdriver is nothing more than an Interface (not a concrete object) even though FirefoxDriver implements that Interface, The above answer about using RemoteWebDriver is probably a better way to go. I'm not a Java expert, but I'm not sure you can TypeCast with an interface in this way. I'm a little rusty at Java at the moment, but this article covers some of what I suspect may be going on here: https://stackoverflow.com/questions/3582804/java-casting-interface-to-class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.