简体   繁体   中英

How can i stop page loading and close browser in Ruby Watir when i takes to much time for page to load?

I have tried different methods that extends the loading time of the browser but still gives me the following error Net::ReadTimeout , I was wondering if it is a way so it can detect the time of the page load and after for example 10 seconds it closes automatically and move to the next process

browser.driver.manage.timeouts.implicit_wait = 40
    browser.driver.manage.timeouts.page_load = 40
    Watir.default_timeout = 40

First line of yours is not necessary when you use WATIR(Waiting for element). It's necessary when you use selenium directly. Because WATIR has it's own timer and it waits for 30 seconds for element interaction.

For the second one(Page Load), you have to use the following line to increase or decrease the page Load timing.Default time out is 60seconds, If you want increase the timing(for an example120), then write the following coe

 client = Selenium::WebDriver::Remote::Http::Default.new
 client.read_timeout = 120
 browser = Watir::Browser.new :firefox, http_client: client

If you want to tell the driver as to you don't want any page load waiting then use the below statement

Watir::Browser.new :firefox,page_load_strategy: 'none'

If you want to wait for Page load to the specified time, If it doesn't load, and you want to close the browser, then write the following code

begin
  browser.goto 'Your Url'
rescue Net::ReadTimeout
  browser.close rescue ''
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM