Make headless browser stop loading page

前端 未结 4 1434
逝去的感伤
逝去的感伤 2021-02-15 12:29

I am using the watir-webdriver ruby gem. It starts the browser (Chrome) and begins to load a page. The page is loading too slowly, and watir-webdriver raises a timeout error. Ho

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 12:44

    I've been fighting with this problem for awhile, I know that this post is from 2012 but I still haven't found anything that solves this issue.. So i made a work around.

    require 'watir-webdriver'
    
    client = Selenium::WebDriver::Remote::Http::Default.new
    client.timeout = 5
    @browser = Watir::Browser.new :firefox, :http_client => client
    
    @browser.goto "twitter.com"
    
    #after the page loads, log in 
    def test    
      begin
         temp = []
         temp = @browser.cookies.to_a
         @browser.goto "twitter.com:81"
      rescue => e
         puts "Browser timed out"
         @browser.close
         @browser = Watir::Browser.start "twitter.com"
    
         temp.each do |me|
           @browser.cookies.add(me[:name], me[:value])
         end
         @browser.refresh 
    
      end
    end
    

    The extra code that saves and restores your cookies will allow you to stay logged into sites you're using. This sucks but its the only work around I can think of. Again this was back in 2012, so if anyone finds anything that works better please correct me.

提交回复
热议问题