Mitmdump不适用于selenium-webDriver

时间:2019-08-04 14:14:52

标签: ruby selenium selenium-webdriver mitmproxy

我将Selenium :: WebDriver :: Remote :: Capabilities.chrome和chromeOptions与--proxy-server一起使用(mitmdump与代理服务器一样使用)。但是当我运行代码并检查ip时,它仍然是我的。

args = [
      "mitmdump",
      "--listen-host", "127.0.0.1",
      "--listen-port", @port,
      "--mode", "upstream:http://#{proxy.ip}:#{proxy.port}",
      "--upstream-auth", #{proxy.login}:#{proxy.password}
    ]

server = ChildProcess.build(*args)
server.start
raise "Oops" unless server.alive?

Capybara.register_driver :selenium do |app|
      caps = Selenium::WebDriver::Remote::Capabilities.chrome(
        "chromeOptions" => {
          "args" => [
            "--headless",
            "--proxy-server=http://127.0.0.1:@port",
            "--disable-dev-shm-usage",
            "--blink-settings=imagesEnabled=true",
            "window-size=1440,900",
            "--no-sandbox"
          ]
        }
      )
      Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: caps)
    end

    Capybara.javascript_driver = :chrome
    Capybara.configure do |config|
      config.default_max_wait_time = 20
      config.default_driver = :selenium
    end

    session = Capybara::Session.new(:selenium)

    session.visit("https://www.2ip.ru")

1 个答案:

答案 0 :(得分:0)

最新的Selenium / Chrome组合默默地忽略了“ chromeOptions”选项,其新语法为“ goog:chromeOptions” https://github.com/SeleniumHQ/docker-selenium/issues/674