I'm trying to run Selenium in headless mode, when using the code below it works fine.
proxy_url = get_random_proxy
proxy = Selenium::WebDriver::Proxy.new http: proxy_url, ssl: proxy_url
caps = Selenium::WebDriver::Options.chrome proxy: proxy
options = Selenium::WebDriver::Chrome::Options.new
# options.add_argument('--no-sandbox')
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument('--disable-infobars')
options.add_argument('--disable-translate')
options.add_argument('--dns-prefetch-disable')
options.add_argument('--headless')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36')
prefs = { prompt_for_download: false, default_directory: '/tmp' }
options.add_preference(:download, prefs)
driver = Selenium::WebDriver.for(:chrome, options: options, capabilities: [caps])
# driver = Selenium::WebDriver.for(:chrome, capabilities: [options, caps])
driver.devtools.new
driver.navigate.to "https://api.ipify.org"
But when replacing driver = Selenium::WebDriver.for(:chrome, options: options, capabilities: [caps])
with driver = Selenium::WebDriver.for(:chrome, capabilities: [options, caps])
it still opens the browser window.
This is the deprecation warning:
Selenium [DEPRECATION] [:browser_options] :options as a parameter for driver initialization is deprecated. Use :capabilities with an Array of value capabilities/options if necessary instead I'm trying to use the latter option because the first one is deprecated in Selenium 4