2016-01-12 21 views
0

使用selenium webdriver自動化網站時,我需要允許地理位置權限向前移動。我無法使用firefox配置文件的功能。如何在使用selenium webdriver的Firefox配置文件中爲網站啓用地理位置權限

Image of the geo-location pop up

像這樣的事情

public static String fileName = "/Users/Arjit/Documents/geoLocation.json"; 
    WebDriver driver; 
    FirefoxProfile profile = new FirefoxProfile(); 
    profile.setPreference("geo.enabled", true); 
    profile.setPreference("geo.provider.use_corelocation", true); 
    profile.setPreference("geo.wifi.uri",newFile(fileName).toURI().toString()); 
    driver = new FirefoxDriver(profile); 
    driver.get("http://www.zoomcar.com"); 

而且geoLocation.json具有

{ 
    "status": "OK", 
    "accuracy": 10.0, 
    "location": { 
     "lat": 12.9525060, 
     "lng": 77.6991510 
    } 
} 
+1

向我們展示如何嘗試使用'capabilities'和'FirefoxProfile' – Andersson

回答

1

我已經試過你的腳本有以下變化和它的工作:

profile.setPreference("geo.prompt.testing", true); 
    profile.setPreference("geo.prompt.testing.allow", true); 
    profile.setPreference("geo.wifi.uri", "file:///C:/Users/.../src/main/data/geoLocation.json"); // add absolute path here 
    driver = new FirefoxDriver(profile); 
    //driver.get("http://www.zoomcar.com"); 
    driver.get("http://html5demos.com/geo"); 

P.S. geoLocation.json與您的一樣,但座標不同。

{ 
    "status": "OK", 
    "accuracy": 10.0, 
    "location": { 
     "lat": 18.976916, 
     "lng": 73.736801 
    } 
} 

Results page

0

硒3.0這會工作。如果你只是想使用相同的配置文件。 你也可以通過在Firefox的地址欄輸入 「about:config」來設置/更改首選項列表,並按Enter鍵。

  FirefoxOptions op = new FirefoxOptions(); 
     op.SetPreference("geo.enabled", false); 
     IWebDriver webDriver = new FirefoxDriver(op); 

在這裏,我關閉每次彈出的地理位置警報,我的測試運行。

相關問題