gpt4 book ai didi

ruby - 如何在 Ruby Selenium 中使用 Chrome 选项?

转载 作者:数据小太阳 更新时间:2023-10-29 07:47:28 25 4
gpt4 key购买 nike

以下片段来自官方页面Ruby Bindings ;然而,它无法工作

  options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-translate')
@driver = Selenium::WebDriver.for :chrome, options: options

错误:

enter image description here enter image description here

最佳答案

对于 Selenium 4 & Chrome <75用户

  options = {
args: ['disable-infobars', 'disable-gpu', 'privileged', 'ignore-certificate-errors', 'no-default-browser-check'],
w3c: true,
mobileEmulation: {},
prefs: {
:protocol_handler => {
:excluded_schemes => {
tel: false,
}
}
},
extensions: [ Base64.strict_encode64(File.open("../your_extension.crx", 'rb').read) ]
}

caps = Selenium::WebDriver::Chrome::Options.new(options: options)
@driver = Selenium::WebDriver.for(:chrome, options: caps)

对于 Selenium 3用户

使用开关定义 chrome 选项

  caps = Selenium::WebDriver::Remote::Capabilities.chrome("desiredCapabilities" => {"takesScreenshot" => true}, "chromeOptions" => {"binary" => "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"})
@driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps, switches: %w[--incognito --screen-size=1200x800]

或者

driver = Selenium::WebDriver.for :chrome, switches: %w[--incognito]

RemoteWebDriver

caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => [ "disable-infobars" ]})
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: caps

Chrome switches list

https://peter.sh/experiments/chromium-command-line-switches/

关于ruby - 如何在 Ruby Selenium 中使用 Chrome 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45275586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com