screen shot for my question如何使用selenium webdriver在mozilla和chrome浏览器中处理Geo Location弹出窗口?
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,所以请帮我解决问题
答案 0 :(得分:2)
不建议使用带有FirefoxProfile对象的firefox驱动程序初始化。我改用了它,添加了相同的首选项。而且对我有用
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);
答案 1 :(得分:1)
使用Selenium 3.x时,geckodriver v0.16.1&在Mozilla Firefox 53.x中,您可以通过在新的Firefox配置文件中设置首选项来禁用地理位置弹出窗口,如下所示:
System.setProperty
driver.get("http://www.google.com");
打开任何其他网址。以下是最小代码的工作集,可以在没有地理位置弹出窗口的情况下打开目标网址。
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/");