Watir: Search for elements on page using multiple attributes

I ran into a situation today where i wanted to scan through a page and return a table based on the table matching 3 attributes


browser.tables.find do |table|
table.class_name == ‘my_class_name’ and
table.cell(:class, ‘class_1_name’).text == ‘some_text_1’ and
table.cell(:class, ‘class_2_name’).text == ‘some_text_2’

This was taking about 3minutes as there were about 86tables on this page under test. I was worried but the tables on this page was gonna increase with time which meant the time for this stage of the test was bound to increase.

In my search for how to search for a single table using multiple attributes:

I found this:


browser.table(:class => ‘my_class_name’, :text => /#{‘some_text_1}/, :text => /#{‘some_text_2}/)

Believe it or not, i got my test time reduced to 3secs, awesome isnt it?


You Might Also Like
comments powered by Disqus