简体   繁体   中英

How to handle Geo location popup using Selenium chromedriver?

When ever launching the web-app in chrome browser using selenium webdriver, Geo-location(Geo Location) Pop up is coming on the top of the browser.

Due to which some of my location based Test Cases are getting failed.

How to handle these kind of scenarios using chromedriver?

"When ever launching the web-app in chrome browser using selenium webdriver, 
Geo-location(Geo Location) Pop up is coming on the top of the browser."

in this case, u may try something like this:

@BeforeMethod
public void clearPopup() {
    driver.navigate().refresh();
    Thread.sleep(2000);//wait until the page is loaded.
    //try to use explicit wait

     try {

            Alert alert = driver.switchTo().alert();                
            alert.dismiss();
           } catch (NoAlertPresentException ex) {
             //System.out.println("No alert for this test case.");
           }        
}

this method will run before all ur testcase and if any popup shows it will dismiss the alert.

I also have go through ur url. when i click on call geolocation api, a pop is shown. U can stop this kind of pop up by doing the followings:

-go to settings of chrome and click on advanced settings.
-than click on content settings under privacy.
-than u will see pop ups and location options.

form there choose what option u want. Choose

"Allow all sites to track ur physical location" 

if u don't want to see the popup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM