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

Viewed 1229

How can I fake/mock the Geolocation in the ChromeDriver through Selenium in 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:

enter image description here

1 Answers

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

I can think of 2 options here

  • 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

  • Set Appium driver with real/emulator device and use
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/commands/session/geolocation/set-geolocation/

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.

Related