Unable to connect to browser using ruby selenium webdriver

后端 未结 3 1973
名媛妹妹
名媛妹妹 2021-01-02 05:01

I tried to run some basic automated tests using ruby selenium webdriver. The same code works perfectly on my home computer, but fails on my work computer which is behind a p

相关标签:
3条回答
  • 2021-01-02 05:32

    Usage of selenium-webdriver behind proxy has browser related specific. In short, you need to find a way of passing proxy settings to the browser instance created by webdriver.

    Below is a code that works with Firefox.

    #Firefox keeps proxy settings in profile.
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile.proxy = Selenium::WebDriver::Proxy.new( :http => "192.168.1.1:3128")
    driver = Selenium::WebDriver.for :firefox, :profile => profile
    
    driver.navigate.to "http://google.com"
    puts driver.title
    driver.quit
    
    0 讨论(0)
  • 2021-01-02 05:46
    require 'rubygems'
    require 'selenium-webdriver'
    ENV['NO_PROXY']="127.0.0.1"
    driver = Selenium::WebDriver.for :firefox
    driver.get "http://google.com"
    
    0 讨论(0)
  • 2021-01-02 05:52

    You probably have HTTP_PROXY (or http_proxy) set in your environment. The next release of selenium-webdriver (2.25) will also honor NO_PROXY/no_proxy (which you can then set to NO_PROXY=127.0.0.1). Until then you can remove the proxy from the Ruby environment before launching the browser:

    ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
    driver = Selenium::WebDriver.for :firefox
    

    If you need the proxy configured for Firefox to communicate with the outside world, you could try something like this:

    proxy = Selenium::WebDriver::Proxy.new(:http => ENV['HTTP_PROXY'] || ENV['http_proxy'])
    ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
    driver = Selenium::WebDriver.for :firefox, :proxy => proxy
    
    0 讨论(0)
提交回复
热议问题