Selenium webdriver 如何使用SeleniumWebDriver处理mozilla和chrome浏览器中的地理位置弹出窗口?

Selenium webdriver 如何使用SeleniumWebDriver处理mozilla和chrome浏览器中的地理位置弹出窗口?,selenium-webdriver,Selenium Webdriver,如何使用SeleniumWebDriver处理mozilla和chrome浏览器中的地理位置弹出窗口 package tiyotesting; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.ope

如何使用SeleniumWebDriver处理mozilla和chrome浏览器中的地理位置弹出窗口

    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自定义配置文件它也不再工作了弹出窗口对我来说是showstopper,因此请帮助我解决问题

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

  • 您必须从下载geckodriver.exe。保存在你的机器上
  • 您必须通过
    System.setProperty
  • 您不需要执行
    driver.get(“http://www.google.com");
    打开任何其他URL
  • 下面是一组最小代码,它可以在没有地理位置弹出窗口的情况下打开预期的URL

    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/"); 
    

  • firefox驱动程序与FirefoxProfile对象的使用初始化已被弃用。我使用了它,添加了相同的首选项。这对我很有效

    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);
    

    我创建了Firefox自定义配置文件它也不再工作了弹出窗口来了它是我的showstopper,所以请帮助我解决问题我无法在google.com中看到地理位置弹出窗口-它为我自动重定向。请考虑提供一个截图的POPUP。我必须附加文件,请编辑您的问题,并附上图像。我编辑和附加先生,先生,我还有一个问题与相同的代码…如何在列表框中选择项目?请帮帮我谢谢你的建议先生