Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 238
Snickbrack Avatar asked May 19 '20 14:05

Snickbrack


People also ask

Can a website detect when you are using Selenium with ChromeDriver?

The answer is YES! Websites can detect the automation using JavaScript experimental technology navigator. webdriver in the navigator interface.

How do I instantiate ChromeDriver?

In order to instantiate the object of ChromeDriver, you can simply create the object with the help of below command. Webdriver driver = New ChromeDriver(); The main motto of the ChromeDriver is to launch Google Chrome. Without that, it is not possible to execute Selenium test scripts in Google Chrome browser.

Does ChromeDriver need Selenium?

As Google Chrome dominates the browser market, the use of a ChromeDriver becomes a must. Selenium WebDriver uses the ChromeDriver to communicate test scripts with Google Chrome.


Video Answer


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.

like image 115
Gravity API Avatar answered Oct 02 '22 17:10

Gravity API