如何允许使用Selenium进行位置访问? [英] How can I allow location access using Selenium?
问题描述
我试图在Java中使用Selenium来获取用户的地理坐标,但是使用IP地址不够准确,因此我想使用此网站
I am trying to use Selenium in Java to get the user's geographical coordinates, but using IP address isn't accurate enough, so i wanted to use this website http://www.whataremycoordinates.com/ , but it isn't working, and I am guessing it is because you have to allow location use, so is there anyway I can allow location use in Selenium, or maybe some other way to get exact geographical coordinates
推荐答案
通常,当站点想要获取此类数据时,浏览器会询问您是否要共享位置.问题是在弹出窗口中,无法使用selenium
控制 .在这种情况下,您需要告诉浏览器,不要打开弹出窗口并允许同时共享您的位置,这样就不会首先打开弹出窗口.
Usually, when a site wants to get this kind of data, a browser asks you if you want to share your location. The question is inside a popup which cannot be controlled with selenium
. In this case, you need to tell the browser, not to open the popup and allow to share your location at the same time so that the popup would not be opened in the first place.
对于Firefox
,您需要:
- 打开网站
- 允许分享您的位置(您也可以选中
about:permissions
来查看设置) - 保存当前的Firefox配置文件
- 使用
FirefoxProfile
指向您之前保存的配置文件启动Firefox
- open the site
- allow to share your location (you can also check
about:permissions
to see the setting) - save the current firefox profile
- start firefox with
FirefoxProfile
pointing to the profile you've saved before
有关更多信息,请参见:
For more information, see:
- 针对Selenium的自定义Firefox配置文件
- 如何使用Selenium 2打开指定的配置文件Firefox Webdriver?
- 如何使用自定义带有Selenium的Firefox个人资料? (Java)(并通过HTML授权窗口)
- 在Firefox中使用Selenium WebDriver更改地理位置
- 网络驱动程序:点击共享位置" Firefox中的按钮
- Custom Firefox Profile for Selenium
- How to open specified profile Firefox with Selenium 2 Webdriver?
- How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)
- Change GeoLocation using Selenium WebDriver in Firefox
- Webdriver: Click "Share Location" button in Firefox
这篇关于如何允许使用Selenium进行位置访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!