Wilco van Esch
Wilco van Esch

Reputation: 457

How can Watir-WebDriver find a class which was updated through JS?

What I'm trying to do is click a 'Next' button on an image slider and verify that it brings me to the next image.

The pagination pips have class "btn dot icon". There is an EventListener which gives the pip of the currently selected slide the class "btn dot icon selected". I can verify this in irb:

irb(main):091:0> @b.span(:class, 'btn dot icon selected').text
=> "Page 0"
irb(main):092:0> @b.span(:text => 'Next', :index => 1).click
=> []
irb(main):093:0> @b.span(:class, 'btn dot icon selected').text
=> "Page 1"

However, running the same through Watir-WebDriver it returns "Page 0" throughout any clicks of 'Next'. Adding an implicit wait does not make a difference.

What might be the issue here?

Note: The 'Next' button matcher looks for the second occurrence (:index => 1) because there is another slider above the one I'm interested in, but this slider does not have the pagination pips (verified through @b.spans(:class => 'btn dot icon').size).

Ruby 1.9.3p545, Watir-WebDriver 0.6.11, Selenium-WebDriver 2.44.0, Firefox 33.1

Upvotes: 0

Views: 94

Answers (1)

Wilco van Esch
Wilco van Esch

Reputation: 457

Turned out to be a simpler solution than I was expecting. Solved it by changing

@b.span(:text => 'Next', :index => 1).click

to

@b.span(:text => 'Next', :index => 1).fire_event("onclick")

Watir-WebDriver was executing a click on the span successfully, but it looks like it can't fire the JavaScript click event on that span. Manually making it fire the JavaScript event works.

Upvotes: 0

Related Questions