>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

Before:

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’
end

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:

After:

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?

Enjoy!!!!!!

Advertisements
This entry was posted in Software Testing and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s