Reputation: 23
I am trying to write automated scripts for a web application using watir. There is a slider in the UI, which has a range from 1 to 11. It is a horizontal div. So, if you press the right arrow key, the number increments by 1, and if you press a left arrow key the number decrements. My problem is when I try to execute the following statements in irb individually, the send_keys
function works fine, but as soon as I move it to a ruby script, it does not execute the send_keys.
assert($b.div(:class, "position").text == "2")
$b.div(:class, "scroll").wait_until_present
$b.div(:class, "scroll").click
$b.div(:class, "scroll").send_keys(:arrow_right)
assert($b.div(:class, "position").text == "3")
The send_keys(:arrow_right)
works if I run separately in irb. When trying to run through a script file, it does not give me any error and remains on the same number, and it just says "Failed assertion, no message given."
The b.div(:class, "scroll").click
is to activate the div on which the the right arrow key is to be pressed.
I'm using watir-webdriver 0.6.2, Firefox 18.0.2, Windows 7 64-bit
Upvotes: 2
Views: 620
Reputation: 349
As you mentioned b.div(:class, "scroll").click
is to activate the div on which the key is to be pressed,
There might be possibilities that this is taking a while to activate the div, and when you are doing that in IRB that is getting proper time to load as it takes time to execute another line, but when you are doing that in script and executing you are performing send_keys
action immediately after clicking on the div, and execution not getting proper time to activate that Div.
Try to give a pause/delay in your script for a while and then try to perform send_keys
.
To give a pause/delay you can use sleep(time_period)
Upvotes: 2