Pra*_*ams 3 ruby selenium selenium-webdriver
下面的摘录来自官方页面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
Run Code Online (Sandbox Code Playgroud)
错误:
对于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)
Run Code Online (Sandbox Code Playgroud)
对于Selenium 3用户
使用开关定义镶边选项
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]
Run Code Online (Sandbox Code Playgroud)
要么
driver = Selenium::WebDriver.for :chrome, switches: %w[--incognito]
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
Chrome开关清单
https://peter.sh/experiments/chromium-command-line-switches/
| 归档时间: |
|
| 查看次数: |
5432 次 |
| 最近记录: |