如何允许使用Selenium进行位置访问? [英] How can I allow location access using Selenium?

查看:192
本文介绍了如何允许使用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:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆