D
D
DigiBeach2020-07-29 18:56:39
ruby
DigiBeach, 2020-07-29 18:56:39

How to connect two options in Watir webdriver?

Hello. In general, I want to use the webdriver setup with a proxy and with a user agent at the same time, I have this. With this option, one thing works, I'm even dumb apparently. Tell me how to make both proxy and driver work?

require 'watir'
require "proxifier/proxy"
require 'proxy_chain_rb'
require 'webdriver-user-agent'

u_proxy = File.readlines("proxy.txt").sample
real_proxy        =   u_proxy
server            =   ProxyChainRb::Server.new
generated_proxy   =   server.start(real_proxy)

proxy = {
    http: generated_proxy,
    ssl:  generated_proxy
  }  

  driver = Webdriver::UserAgent.driver(:browser => :chrome,:agent => :random)
  browser = Watir::Browser.new(driver)
  browser = Watir::Browser.new(:chrome, proxy: proxy)
  browser.goto("https://2ip.ru/")
  sleep(25)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DigiBeach, 2020-08-02
@DigiBeach

I figured it out myself.

require 'watir'
require 'proxy_chain_rb'
require 'selenium-webdriver'

USERAGENT = File.readlines("user_agents.txt").sample
options = Selenium::WebDriver::Chrome::Options.new
options.add_emulation(user_agent: (USERAGENT))

u_proxy = File.readlines("proxy.txt").sample
real_proxy        =   u_proxy
server            =   ProxyChainRb::Server.new
generated_proxy   =   server.start(real_proxy)

proxy = {
    http: generated_proxy,
    ssl:  generated_proxy
  }  
  caps = Selenium::WebDriver::Remote::Capabilities.chrome(:proxy => proxy)
  driver = Selenium::WebDriver.for :chrome, :desired_capabilities => caps, options: options
  driver.execute_script('return navigator.userAgent')
  driver.get("https://raskruty.ru/tools/ip/")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question