1
votes

The code

for i in 0..10  
  $browser.link(:id => "send_link").fire_event("onclick")
  puts "Click #" + i.to_s
end

only displays "Click #0" to the console before crashing with an unable to locate element error. I need it to click the link 10 times, even while the page is trying to load from the first click. Is there a way to do this using watir-webdriver, or will I have to use the win32api to hijack the mouse and do a hard click?

Edit: For the time being, I attempted to get around this by using the hardware click method that worked for a different issue I had using watir and IE8, but it doesn't seem to work with watir-webdriver and Firefox 4.

http://wiki.openqa.org/display/WTR/Right+Click+an+Element

1
what happens when you click the link? is it taking the browser to another page?Chuck van der Linden
it's a side issue to your real question, but you realize you have a 'fencepost' error in the loop you specify above? It's going to iterate 11 times, not 10. you want to do "for i in 0..9" or "for i in 1..10" or something like '10.times do |i|' instead of the current loop you have.Chuck van der Linden
When I click the link, a ruby function is ran that does processing on the server side. A spinner animates on the screen while the browser waits for the processing to finish.Roderick
OK so it's not actually loading a page, but it is making a request to the server under the covers. and most likely the spinner is just an animated graphic file that has its visibility altered until the client side code gets back the response it needs from the server.. unless, the spinner isn't actually modal or in some kind of popup is it? (I'm trying to figure out a good reason for the behavior you described) I'm starting to think that from the DOM perspective perhaps the page has been altered such that it is disabled or no longer existsChuck van der Linden
Usually, "unable to locate element" errors cause the test to crash immediately, but in this case it sends the click, then waits for the next page to load before crashing.Roderick

1 Answers

0
votes

have you tried using .click_no_wait to see if that will work for you?

10.times do |i|  
  $browser.link(:id => "send_link").click_no_wait
  puts "Click #" + i.to_s
end