尝试这个..
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)
还要验证您是否Ask me when a site tries to track my physical location (recommended)
选中了 . 下的选项Settings -> Advanced Settings -> Privacy -> Content Settings -> Location
。
更新:
再试一次。。
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)