'How can I handle Geo Location popup in mozilla and chrome browser using selenium webdriver?
Please, see the following screenshot:
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
Solution 1:[1]
While working with Selenium 3.x, geckodriver v0.16.1 & Mozilla Firefox 53.x, you can disable the Geo Location popup by setting the preferences in the new Firefox profile as follows:
- You have to download the geckodriver.exe from here. Save it on your machine.
- You have to mention the absolute path of the geckodriver.exe through
System.setProperty
- You don't require to do
driver.get("http://www.google.com");
to open any other URL. Here is the working set of minimal code which opens the intended URL without the Geo Location popup.
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe"); FirefoxProfile geoDisabled = new FirefoxProfile(); geoDisabled.setPreference("geo.enabled", false); geoDisabled.setPreference("geo.provider.use_corelocation", false); geoDisabled.setPreference("geo.prompt.testing", false); geoDisabled.setPreference("geo.prompt.testing.allow", false); WebDriver driver=new FirefoxDriver(geoDisabled); driver.get("http://ec2-35-154-164-82.ap-south-1.compute.amazonaws.com/tiyorelease3/");
Solution 2:[2]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Sergey Vyacheslavovich Brunov |