如何使用硒铬驱动程序处理地理位置弹出窗口

How to handle Geo location popup using Selenium chromedriver?

本文关键字:地理位置 窗口 处理 驱动程序 何使用      更新时间:2023-09-26

当使用selenium网络驱动程序在chrome浏览器中启动Web应用程序时,地理位置(地理位置)弹出窗口出现在浏览器顶部。

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

如何使用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.");
           }        
}

此方法将在所有测试用例之前运行,如果有任何弹出窗口显示,它将消除警报。

我也浏览了你的网址。 当我单击呼叫地理位置 API 时,会显示一个弹出窗口。您可以通过执行以下操作来停止此类弹出窗口:

-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" 

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