Search code examples
c#seleniumselenium-webdriverfirefoxgeckodriver

setPreference method of FirefoxOptions is not getting recognized through Selenium C#


I am pretty new to C# and integrating with firefox.

So this might be a very basic newbie question :)

I have this code:

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

FirefoxOptions options = new FirefoxOptions();

options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\Windows\\temp");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
options.setPreference("pdfjs.disabled", true);  // disable the built-in PDF viewer

The setPreference is marked with red. It is not recognized.

I have following installed:

enter image description here

enter image description here

enter image description here

What is missing?


Solution

  • FirefoxOptions.SetPreference Method (String, Int32)

    FirefoxOptions.SetPreference Method (String, Int32) defines:

    public void SetPreference(
        string preferenceName,
        int preferenceValue
    )
    

    So you need to replace:

    options.setPreference("browser.download.folderList", 2);
    

    With:

    options.SetPreference("browser.download.folderList", 2);
    

    FirefoxOptions.SetPreference Method (String, String)

    FirefoxOptions.SetPreference Method (String, String) defines:

    public void SetPreference(
        string preferenceName,
        string preferenceValue
    )
    

    So you need to replace:

    options.setPreference("browser.download.dir", "C:\\Windows\\temp");
    options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
    

    With:

    options.SetPreference("browser.download.dir", "C:\\Windows\\temp");
    options.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
    

    FirefoxOptions.SetPreference Method (String, Boolean)

    FirefoxOptions.SetPreference Method (String, Boolean) defines:

    public void SetPreference(
        string preferenceName,
        bool preferenceValue
    )
    

    So you need to replace:

    options.setPreference("browser.download.useDownloadDir", true);
    options.setPreference("pdfjs.disabled", true); 
    

    With:

    options.SetPreference("browser.download.useDownloadDir", true);
    options.SetPreference("pdfjs.disabled", true);