How can I handle Geo Location popup in mozilla and chrome browser using selenium webdriver?

Viewed 2776

Please, see the following screenshot:

screen shot for my question

How can I handle Geo Location popup in mozilla and chrome browser using selenium webdriver?

    package tiyotesting;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.firefox.internal.ProfilesIni;
    import org.openqa.selenium.support.ui.Select;
    public class Citydropdownlist {
        public static void main(String[] args) throws InterruptedException {
            WebDriver driver = new FirefoxDriver();
            driver.get("http://www.google.com");
            driver.get("http://ec2-35-154-164-82.ap-south-1.compute.amazonaws.com/tiyorelease3/");
            WebElement ListBox = driver.findElement(By.id("supported_city_label"));
            ListBox.sendKeys("Ahmedabad");
            ListBox.sendKeys(Keys.ENTER);
        }
    }

I created Firefox custom profile it is also not working again the popup came it is showstopper for me, so please help me to resolve the issue

2 Answers

The usage initialization of firefox Driver with a FirefoxProfile object has been deprecated. I've used that instead, adding the same preferences. And It worked for me

File gecko = new File("C:\\geckodriver\\geckodriver.exe");

FirefoxOptions ffopt = new FirefoxOptions()
    .addPreference("dom.webnotifications.enabled", false)
    .addPreference("geo.enabled", false)
    .addPreference("geo.provider.use_corelocation", false)
    .addPreference("geo.prompt.testing", false)
    .addPreference("geo.prompt.testing.allow", false);


System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
WebDriver driver = new FirefoxDriver(ffopt);
Related