【问题标题】:Selenium Grid 2 - Chromedriver does not start a new profile on a new runSelenium Grid 2 - Chromedriver 不会在新运行时启动新配置文件
【发布时间】:2013-04-08 04:17:27
【问题描述】:

在使用rubyselenium grid 2 在Chrome 上使用selenium webdriver (chromedriver) 测试网站时,我手动点击了Allow 来跟踪我的位置。

从那时起,每次新的运行都以 Chrome 浏览器跟踪我的位置开始,不再请求许可。

据我了解,这不应该发生,因为 Selenium 应该创建一个新的配置文件并且不记得上次运行中的任何用户交互。

我还尝试以管理员身份(手动)打开 Chrome 浏览器并更改设置以忘记为正在测试的站点的位置服务设置的任何权限。但这也无济于事。

我也尝试过重启电网,但也没有用。

有谁知道如何让浏览器忘记我的权限?

更新

启动驱动的代码

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

【问题讨论】:

  • 你是如何创建(初始化)驱动程序的?
  • 如果你的意思是 selenium webdriver 那么是的。
  • 我更新了问题

标签: ruby selenium webdriver selenium-webdriver selenium-chromedriver


【解决方案1】:

试试这个..

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)

还要确认您在Settings -> Advanced Settings -> Privacy -> Content Settings -> Location 下选中了Ask me when a site tries to track my physical location (recommended) 选项。

更新:

再试一次..

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)

【讨论】:

  • 所以问题是,我更改的任何设置(在 selenium 运行期间)都不会保存以供下次运行。此外,我手动更改的 Chrome 浏览器设置在脚本创建的浏览器上也看不到。
  • 试过你的解决方案,但它并没有清除保存的位置
  • @amey- 我认为您可以尝试使用ChromeOptions,如那里所述。
  • 不知道怎么翻译成ruby,有什么建议吗?
【解决方案2】:

试试这个本地 WebDriver 修复:

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

要远程执行此操作,我认为它可能看起来像这样:

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

有关使用开关https://code.google.com/p/selenium/wiki/RubyBindings#Chrome的信息,请参阅 RubyBindings 文档

您可以在此处查看 Chrome 开关列表:http://peter.sh/experiments/chromium-command-line-switches/

更新

看起来 Chromedriver 需要先关闭测试默认设置,然后才能设置某些设置(如地理位置跟踪)(根据此处找到的 ChromeDriver Capabilities wiki 的修订版:http://wiki.chromedriver.googlecode.com/git-history/c790ec6b0b32a31a8797a0fa97b7f4dccb4f5da4/CapabilitiesAndSwitches.wiki)。

我更新了上面的代码以包含设置为关闭测试默认值的配置(请参阅http://code.google.com/p/chromium/issues/detail?id=113884http://code.google.com/p/selenium/issues/detail?id=4622)。

请确保您使用的是 selenium-webdriver 2.26.0 或更高版本。

【讨论】:

  • 基于两个链接,代码看起来正确。但不幸的是它不起作用。
猜你喜欢
  • 1970-01-01
  • 2015-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-12
  • 2023-03-25
  • 2012-03-18
  • 1970-01-01
相关资源
最近更新 更多