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

查看:92
本文介绍了如何通过 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/移动仿真

我可以在这里想到 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.mdhttps://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天全站免登陆