0

While testing a website on Chrome using selenium webdriver (chromedriver) with ruby and selenium grid 2, I manually clicked on Allow to track my location.

Since then every new run starts off with the Chrome browser tracking my location and not asking for permission anymore.

In my understanding that should not happen, as Selenium should create a new profile and not remember any user interactions in the previous run.

I have also tried to open the Chrome Browser as an admin (manually) and change the settings to forget any permissions set for location services for the site being tested. But that has not helped either.

I have also tried to restart the grid but that has not helped either.

Does anyone know how do I make the browser forget my permission?

UPDATE

Code to start the driver

@driver = Selenium::WebDriver.for(:remote, :url => @sel_grid_url, :desired_capabilities => @browser)
3
  • How are you creating(initializing) the driver?
    – vidit
    Apr 15, 2013 at 22:16
  • If you mean the selenium webdriver then yes.
    – Amey
    Apr 15, 2013 at 22:16
  • I made an update to the question
    – Amey
    Apr 15, 2013 at 22:20

2 Answers 2

1

Try this..

profile = Selenium::WebDriver::Chrome::Profile.new

data = profile.as_json

caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps['chromeOptions'] = {
  'profile'    => data['zip'],
  'extensions' => data['extensions']
}

driver = Selenium::WebDriver.for(:remote, :url => @sel_grid_url, :desired_capabilities => caps)

Also verify that you have Ask me when a site tries to track my physical location (recommended) option checked, under Settings -> Advanced Settings -> Privacy -> Content Settings -> Location.

Update:

Another try..

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = "/path/to/dir"
profile['profile.managed_default_content_settings.geolocation'] = 2 #Try 1 and 0 as well


data = profile.as_json

caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps['chromeOptions'] = {
  'profile'    => data['zip'],
  'extensions' => data['extensions']
}

driver = Selenium::WebDriver.for(:remote, :url => @sel_grid_url, :desired_capabilities => caps)
9
  • So the problem is, any settings that I change (during the selenium run) do not get saved for the next run. Also the Chrome browser settings that I change manually, are not seen on the browser created by the script.
    – Amey
    Apr 15, 2013 at 22:34
  • Tried your solution, and it does not clear the saved location
    – Amey
    Apr 15, 2013 at 22:35
  • Will this code.google.com/p/chromedriver/issues/detail?id=138 be of any help?
    – Amey
    Apr 15, 2013 at 22:36
  • @amey- I think you can try using ChromeOptions as detailed there.
    – vidit
    Apr 15, 2013 at 22:39
  • I am not sure how to translate it to ruby, any suggestions?
    – Amey
    Apr 15, 2013 at 22:39
0

Try this for a local WebDriver fix:

@driver = Selenium::WebDriver.for(:chrome, :no_website_testing_defaults => true, :switches => %w[--disable-geolocation])

To do so remotely, I think it would probably look something like this:

caps = Selenium::WebDriver::Remote::Capabilities.chrome(:no_website_testing_defaults => true, :switches => %w[--disable-geolocation])
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps)

Please see the RubyBindings documentation for information on using switches https://code.google.com/p/selenium/wiki/RubyBindings#Chrome

You can view a list of Chrome switches here: http://peter.sh/experiments/chromium-command-line-switches/

Update

Looks like Chromedriver needs to turn testing defaults off first before some settings (like geolocation tracking) can be set (this according to a revision of the ChromeDriver Capabilities wiki found here: http://wiki.chromedriver.googlecode.com/git-history/c790ec6b0b32a31a8797a0fa97b7f4dccb4f5da4/CapabilitiesAndSwitches.wiki ).

I updated the code above to include the config to set to turn the testing defaults off (see http://code.google.com/p/chromium/issues/detail?id=113884 and http://code.google.com/p/selenium/issues/detail?id=4622 ).

Please ensure that you are using selenium-webdriver 2.26.0 or greater.

1
  • based on the two links the code looks right. But unfortunately it doesn work.
    – Amey
    Apr 26, 2013 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.