如何通过C#中的Selenium伪造/模拟ChromeDriver中的地理位置? [英] How can I fake/mock the Geolocation in the ChromeDriver through Selenium in C#?

查看:224
本文介绍了如何通过C#中的Selenium伪造/模拟ChromeDriver中的地理位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过C#中的Selenium伪造/模拟ChromeDriver中的地理位置?

How can I fake/mock the Geolocation in the ChromeDriver through Selenium in C#?

我仅是Python和Java的示例,但由于使用的函数不存在,因此我无法将代码转换"为C#.

I only examples for Python and Java but I cannot "translate" the code to C# because the used functions do not exist.

这是我要执行的操作的示例图像:

This is a example image of what I want to do:

推荐答案

根据官方说法,似乎尚不支持. https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation

According to official, it seems not supported yet. https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation

我在这里可以想到2种选择

I can think of 2 options here

  • 尝试使用 localState 功能查找是否可以使用Chrome状态文件.请注意, 您不能在运行时对其进行更改 .
  • Try and find if it possible using Chrome State file, using localState capability. Note, you cannot change it on runtime.

https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md https://chromedriver.chromium.org/capabilities

  • 使用真实/仿真器设备设置Appium驱动程序并使用
self.driver.set_location(49, 123, 10)

driver.Location.Altitude = 94.23;
driver.Location.Latitude = 121.21;
driver.Location.Longitude = 11.56;

http://appium.io/docs/en/命令/会话/地理位置/设置地理位置/

随时更改位置.我认为这是最好的方法,即使只使用Chrome而不是配置Appium服务器也更容易.

To change the location whenever you like. I think this is the best way to do it anyway, even if it is easier to just use Chrome instead of configure Appium server.

这篇关于如何通过C#中的Selenium伪造/模拟ChromeDriver中的地理位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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