How to Disable Wait Time for Watir

Is it possible to disable wait time for watir?

The waiting for the page to load is controlled by the page load strategy. By default, it is set to "normal", which waits for the document readiness state to be "complete". You can set the strategy to "none" to remove the waiting. Some of the browsers/drivers also support an "eager" strategy that waits for the browser to be in the "interactive" state.

require 'webdrivers'
require 'watir'

browser = Watir::Browser.new :chrome, page_load_strategy: 'none'
browser.goto 'www.google.com'
p browser.ready_state
#=> "loading"

See https://w3c.github.io/webdriver/#navigation for more details.

making 'some_element'.present? in watir wait for less than 5 secs

I believe you are asking how to shorten the length of time before timeout, by default its set to 30 seconds, see below on how to customize that time.

According to http://watirwebdriver.com/waiting/

Explicit waits

There are four built in methods that you can use to make your waiting experience more pleasant (and remove those evil sleep statements from your code)

Watir::Wait.until { ... }: where you can wait for a block to be true
object.when_present.set: where you can do something when it’s present
object.wait_until_present:; where you just wait until something is present
object.wait_while_present:; where you just wait until something disappears
The default timeout for all these methods is 30 seconds, but your can pass an argument to any of these to increase (or decrease) it as needed.

and http://rdoc.info/gems/watir-webdriver/Watir/EventuallyPresent

- (Object) wait_until_present(timeout = nil)

Waits until the element is present.

Examples:

browser.button(:id => 'foo').wait_until_present
Parameters:
timeout (Fixnum) (defaults to: nil) — seconds to wait before timing out

- (Object) wait_while_present(timeout = nil)

Waits while the element is present.

Examples:

browser.button(:id => 'foo').wait_while_present
Parameters:
timeout (Integer) (defaults to: nil) — seconds to wait before timing out

- (Object) when_present(timeout = nil)

Waits until the element is present.

Examples:

browser.button(:id => 'foo').when_present.click
browser.div(:id => 'bar').when_present { |div| ... }
browser.p(:id => 'baz').when_present(60).text
Parameters:
timeout (Fixnum) (defaults to: nil) — seconds to wait before timing out

How do I change the page load Timeouts in Watir-Webdriver (timeout in .click method)

I'd try upping the client timeout:

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 180 # seconds – default is 60

b = Watir::Browser.new :firefox, :http_client => client

Watir wait_until_present times out instead of returning false

I think I'm going to give in and leave the sleeps.

(Ignore the random changes in the class and id names throughout my post. Also snake_case vs. camelCase. I didn't write it this way. Trust that I'm successfully getting to the HTML elements in question.)

unknown error: Element is not clickable at point (550, 565). 
Other element would receive the click: <div id="dashboard-loading-screen" class="loading-page-backdrop ng-scope"
ng-if="pageLoading || gridLoading"></div> (Selenium::WebDriver::Error::UnknownError) (Session info: chrome=41.0.2272.76)

Here's a sanitized version of the entire test that's driving me crazy. I don't have the loading issue in debug mode because of course when I'm debugging it has plenty of time to load, so I had to throw in a bunch of puts to figure out what line it was failing on.

Also note that I didn't write the original version of this test, I'm just trying to get it to assert correctly.

def dashboard_rowsPerPage_next(targetRows)
begin
dashboard_rowsPerPage_internal(targetRows) #click drop-down to choose num of rows/page
browser.scroll.to :bottom
beforeRowsText = $browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 1

#I put this instead of wait_while_present
if (puts browser.html.include?("loading-page-backdrop ng-scope"))
Watir::Wait.while { browser.html.include? "loading-page-backdrop ng-scope"}
end
puts 'a'
puts browser.html.include?("loading-page-backdrop ng-scope")
puts browser.html.include?("loading-page-backdrop ng-scope")

#here's where I get the error message
browser.span(:class, "k-icon k-i-arrow-e").when_present.click
puts 'b'
puts browser.html.include?("loading-page-backdrop ng-scope")

if (puts browser.html.include?("loading-page-backdrop ng-scope"))
Watir::Wait.while { browser.html.include? "loading-page-backdrop ng-scope"}
end

puts browser.html.include?("loading-page-backdrop ng-scope")
puts 'c'
puts browser.html.include?("loading-page-backdrop ng-scope")
browser.scroll.to :bottom
puts browser.html.include?("loading-page-backdrop ng-scope")
afterRowsText = browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 2
puts 'd'
Watir::Wait.while { browser.html.include? "dashboard-loading-screen"}

if (!(beforeRowsText.eql? afterRowsText)) #page 2 text should not be the same as page 1 text
screenCapture()
assertPassed()
else
screenCapture()
assertFailed()
end
# rescue
# screenCapture()
# increment_failed()
end
end

So my output is: (comments added for clarity)

true #should wait while loading image is visible before puts 'a'
a
true #this means the loading page is still visible, while isn't working
true
unknown error: Element is not clickable at point (550, 565).
Other element would receive the click: <div id="dashboard-loading-screen" class="loading-page-backdrop ng-scope"
ng-if="pageLoading || gridLoading"></div> (Selenium::WebDriver::Error::UnknownError) (Session info: chrome=41.0.2272.76)

I checked the values of beforeRowsText and afterRowsText and it's getting those values correctly.

So I'm going to do this instead, because I'm weak:

def dashboard_rowsPerPage_next(targetRows)
begin
dashboard_rowsPerPage_internal(targetRows) #click drop-down to choose num of rows/page
browser.scroll.to :bottom
beforeRowsText = $browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 1
sleep 10
browser.span(:class, "k-icon k-i-arrow-e").when_present.click
sleep 10
browser.scroll.to :bottom
afterRowsText = browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 2

if (!(beforeRowsText.eql? afterRowsText)) #page 2 text should not be the same as page 1 text
screenCapture()
assertPassed()
else
screenCapture()
assertFailed()
end
rescue
screenCapture()
increment_failed()
end
end

Wait no, nevermind. It works with 25 rows per page but I get the same error on 50 rows per page.

How to use watir-webdriver to wait for page load

I don't know if they're the best way, but this is how I'm handling this for waiting for an updating div to clear:

while browser.div(:id=>"updating_div").visible? do sleep 1 end

This is how I handle waiting for something to display:

until browser.div(:id=>"some_div").exists? do sleep 1 end

Stop loading page watir-webdriver

You can use the Timeout class to force it to give up after waiting a reasonable amount of time (and this is internally how Watir performs it's waits as well)

begin
Timeout::timeout(10) do
# perform actions that may hang here
end
rescue Timeout::Error => msg
put "Recovered from Timeout"
end

How do I use Watir::Waiter::wait_until to force Chrome to wait?

Do this first:

require "watir-webdriver/wait"

Then try these:

1

Watir::Wait.until { ... }

2

browser.text_field(:id => 'username').when_present.set("name")

3

browser.text_field(:id => 'username').wait_until_present

Note that "present" here means "the element both exists and is visible".

How do I delay selecting from a dropdown until it's populated?

You can use the when_present to wait until the option is present before selecting it. Basically, Watir will wait up to 30 seconds for the option to appear. If it appears sooner than 30 seconds it will proceed with the action (ie select). Otherwise, a timeout exception is thrown.

@browser.select_list(:id, "ddlCompanyName").option(:text => company).when_present.select

Note that the above assumes that company is the text of the option.

Another option is to wait for anything to appear in the dropdown.

@browser.wait_until{  @browser.select_list(:id, "ddlCompanyName").options.length > 0 }


Related Topics



Leave a reply



Submit