disable notification for allowing my location using selenium

504 views Asked by At

I am trying to initialize the FirefoxDriver so it can disable the notification of a website for allowing my location. I searched and found this code. But when putting ffprofile on FirefoxDriver() it says cannot resolve constructor.

System.setProperty(Utility.MOZILLA_DRIVER, Utility.MOZILLA_PATH);
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("javascript.enabled", false);
driver = new FirefoxDriver(ffprofile);
driver.manage().window().maximize();

Utility class is here:

 public class Utility { 
    public static final String MOZILLA_PATH="C:\\SeleniumDrivers\\firefox\\geckodriver.exe"‌​; 
    public static final String MOZILLA_DRIVER="webdriver.gecko.driver"; 
    }

The error is like this when running it:

Error:(16, 18) java: no suitable constructor found for FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.Capabilities) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.Capabilities)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.firefox.FirefoxOptions) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.firefox.FirefoxOptions)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.firefox.GeckoDriverService) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.firefox.GeckoDriverService)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.firefox.XpiDriverService) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.firefox.XpiDriverService)
1

There are 1 answers

0
undetected Selenium On

While working with Selenium 3.8.1 you can use the FirefoxOptions Class which extends org.openqa.selenium.MutableCapabilities to work with FirefoxProfile as follows :

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

public class FirefoxProfile_new {

    public static void main(String[] args) {

        System.setProperty(Utility.MOZILLA_DRIVER, Utility.MOZILLA_PATH);
        FirefoxOptions options = new FirefoxOptions();
        options.setProfile(new FirefoxProfile());
        WebDriver driver = new FirefoxDriver(options);
        driver.get("https://www.google.com");
    }
}