ruby selenium webdriver proxy with authentication

  1. Install the 'selenium-webdriver' gem in your Ruby project using the following command: gem install selenium-webdriver.

  2. Require the necessary libraries in your Ruby script by adding the following lines at the beginning of your code:

require 'selenium-webdriver'
require 'uri'
require 'net/http'
  1. Define the proxy server address and port, as well as the username and password for authentication:
proxy_address = 'your_proxy_address'
proxy_port = 'your_proxy_port'
proxy_username = 'your_username'
proxy_password = 'your_password'
  1. Create a new instance of the Selenium WebDriver with the proxy settings:
proxy = Selenium::WebDriver::Proxy.new(
  http: "#{proxy_username}:#{proxy_password}@#{proxy_address}:#{proxy_port}",
  ssl: "#{proxy_username}:#{proxy_password}@#{proxy_address}:#{proxy_port}"
)
  1. Configure the WebDriver to use the proxy:
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(proxy: proxy)
driver = Selenium::WebDriver.for :chrome, desired_capabilities: capabilities
  1. Now you can use the WebDriver instance to navigate to websites and perform actions with the proxy and authentication settings applied.