0

I am facing this issue when i want to set Firefox preferences as follows :

public class MyTest{
    
    public WebDriver driver;
    public String baseUrl;
    
    @BeforeSuite
    public void beforeSuite() {
        driver = new FirefoxDriver(); 
        FirefoxOptions options = new FirefoxOptions();
        //FirefoxProfile profile = new FirefoxProfile();
        options.addPreference("browser.download.folderList", 1);
        options.addPreference("browser.download.dir", "C:\\Downloads");
        options.addPreference("browser.download.useDownloadDir", true);
        options.addPreference("browser.download.viewableInternally.enabledTypes", "");
        options.addPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf;text/plain;application/text;text/xml;application/xml");
        options.addPreference("pdfjs.disabled", true);

        WebDriver driver = FirefoxDriver(options);
       //some other code

And the issue is for FirefoxDriver(options) . It underlines The method FirefoxDriver(FirefoxOptions) is undefined for the type MyTest

Anyone can give a support on that ?

Chaoui05
  • 288
  • 1
  • 2
  • 11

3 Answers3

0

Ensure that you have the following import:

import org.openqa.selenium.firefox.FirefoxOptions;

As well as set the path of the GeckoDriver using the System.setProperty() line as follows:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");

Additionally, to make the FirefoxOptions put into effect, you need to remove the line:

driver = new FirefoxDriver();

and finally change the line:

WebDriver driver = FirefoxDriver(options);

as:

driver = FirefoxDriver(options);

Historically this error message...

FirefoxDriver(FirefoxOptions) is undefined for the type MyTest

...was observed earlier due to:

  • Co-existance of older versions of Selenium.
  • Incompatibility between the version of the binaries you are using.

Solution

Ensure that:

  • JDK is upgraded to current levels JDK 8u271.
  • Selenium is upgraded to current levels Version 3.141.59.
  • GeckoDriver is upgraded to GeckoDriver v0.28.0 level.
  • Firefox is upgraded to current Firefox v78.0.2 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Execute your Test as a non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

you can try.

WebDriverManager.firefoxdriver().setup();

0

Remove first

    driver= new Firefoxdriver()

And change last line as

   WebDriver driver = new FirefoxDriver(options);

If you don't call new you are referring to a function called FirefoxDriver which doesn't ,

You are creating an object of class FirefoxDriver so you should use new keyword

PDHide
  • 18,113
  • 2
  • 31
  • 46