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

后端 未结 2 1961
灰色年华
灰色年华 2020-12-20 03:44

screen shot for my questionHow can I handle Geo Location popup in mozilla and chrome browser using selenium webdriver?

    package tiyotesting;
    import ja         


        
相关标签:
2条回答
  • 2020-12-20 04:04

    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);
    
    0 讨论(0)
  • 2020-12-20 04:09

    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. 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/"); 
      
    0 讨论(0)
提交回复
热议问题