Javascript 如何使用Selenium chromedriver处理地理位置弹出窗口?

Javascript 如何使用Selenium chromedriver处理地理位置弹出窗口?,javascript,selenium-webdriver,selenium-chromedriver,Javascript,Selenium Webdriver,Selenium Chromedriver,当使用selenium webdriver在chrome浏览器中启动web应用程序时,地理位置(Geo location)弹出窗口将出现在浏览器顶部 因此,我的一些基于位置的测试用例失败了 如何使用chromedriver处理此类场景 "When ever launching the web-app in chrome browser using selenium webdriver, Geo-location(Geo Location) Pop up is coming on the top

当使用selenium webdriver在chrome浏览器中启动web应用程序时,地理位置(Geo location)弹出窗口将出现在浏览器顶部

因此,我的一些基于位置的测试用例失败了

如何使用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."
在这种情况下,您可以尝试以下操作:

@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.");
           }        
}
此方法将在所有ur测试用例之前运行,如果任何弹出窗口显示,它将关闭警报

我还通过你的网址。当我单击CallGeolocationAPI时,会显示一个pop。您可以通过执行以下操作来停止此类弹出:

-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.
从那里选择你想要的选项。选择

"Allow all sites to track ur physical location" 

如果您不想看到弹出窗口。

您能分享HTML代码吗。。如果可能,链接或类似示例。。弹出窗口的图像等。。如果你启动这个电子商务网站,它将帮助我们更好地帮助你。链接:www.mobile.Kohls.com。地理位置弹出窗口将出现。如果您使用的是appium,则可以查看,然后添加功能AutoAcceptlerts,因为此链接在我这边不起作用。。可能您正在使用VPN,因此我们无法访问sameNo。我们没有使用Appium。我们正在使用SeleniumChrome驱动程序在chrome浏览器中运行webapplication