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

19

本文介绍了如何通过 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 中的地理位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14