Setting geolocation in Firefox using RSelenium

Viewed 186

I am using RSelenium on my EC2 server for several projects.
I am trying to set automatically the location in the parameters of my Firefox profile but I am not sure of where and how to include them.
I would assume somewhere in the makeFirefoxProfile function but I am not sure.

fprof <- makeFirefoxProfile(list("?"))

remDr <- remoteDriver(remoteServerAddr = "ec2-XX-XX-XXX-XX.eu-west-3.compute.amazonaws.com", port = 4445L, extraCapabilities = fprof)

remDr$open()

Any idea how this should be done ? Thanks!

[EDIT 1]: My Firefox profile information seems to be located in this folder: enter image description here

2 Answers

Try the following instead (it worked for me). I used the args extra capability to pass the profile directory to the driver:

remDr <- remoteDriver(remoteServerAddr = "ec2-XX-XX-XXX-XX.eu-west-3.compute.amazonaws.com", port = 4445L, extraCapabilities = list("args", "--profile /your/profile/directory"))

Setting up the location automatically can be achieved easily using and ChromeDriver through for .

Chrome Devtools

Selenium 4 alpha versions have introduced to us the native support for Chrome DevTools Protocol through DevTools interface which helps us getting Chrome Development properties such as Application Cache, Fetch, Network, Performance, Profiler, Resource Timing, Security and Target CDP domains etc.

To set the location within Chrome Browsing Context you can use the following solution:

  • solution:

    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.devtools.DevTools;
    
    public void geoLocationTest(){
      ChromeDriver driver = new ChromeDriver();
      Map coordinates = new HashMap()
      {{
          put("latitude", 50.2334);
          put("longitude", 0.2334);
          put("accuracy", 1);
      }};    
      driver.executeCdpCommand("Emulation.setGeolocationOverride", coordinates);
      driver.get("ec2-XX-XX-XXX-XX.eu-west-3.compute.amazonaws.com");
    } 
    
Related