如何使用硒webdriver在mozilla和chrome浏览器中处理“地理位置"弹出窗口?

如何使用硒webdriver在mozilla和chrome浏览器中处理“地理位置

问题描述:

我的问题的屏幕截图如何在mozilla和chrome浏览器使用硒webdriver?

screen shot for my questionHow 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);
        }
    }

我创建了Firefox自定义配置文件,该配置文件也无法再使用,弹出窗口对我来说是最便宜的,所以请帮助我解决问题

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

在使用Selenium 3.x时,geckodriver v0.16.1&在Mozilla Firefox 53.x中,您可以通过在新的Firefox配置文件中设置首选项来禁用地理位置"弹出窗口,如下所示:

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:

  1. 您必须从此处下载geckodriver.exe.将其保存在您的计算机上.
  2. 您必须提及通过System.setProperty
  3. 的geckodriver.exe的绝对路径.
  4. 您无需执行driver.get("http://www.google.com");即可打开任何其他URL.
  5. 这是最小代码的工作集,该代码可以打开预期的URL而没有地理位置"弹出窗口.

  1. You have to download the geckodriver.exe from here. Save it on your machine.
  2. You have to mention the absolute path of the geckodriver.exe through System.setProperty
  3. You don't require to do driver.get("http://www.google.com"); to open any other URL.
  4. 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/");