watir-nokogiri
by Željko Filipin
At Test Automation Bazaar Aliaksandr Ikhelis gave a lightning talk Watir-Webdriver is slow (did you know that?). He talked about the speed problem he had when watir-webdriver was locating elements via regular expression on big pages. (He also reported the issue at GitHub.)
Recently I have started working on a new project that had a similar speed problem, so I remembered Aliaksandr's talk. I found a solution using Nokogiri.
For example, you have to iterate over all div
elements that have id
attribute starting with id
. Then, you have to do something with the last element.
The page that looks like this:
Watir code for iterating over elements and clicking the last one could look something like this.
You could do exactly the same thing using Watir and Nokogiri.
The speed improvements is noticeable. For example, this script will click the last div
using Nokogiri in about 0.2 seconds and using Watir in about 15 seconds.
Output:
There is a way to speed things up using just the Watir API, but I wanted to provide an example code if Watir API is sometimes too slow for your taste.
You can find more code at watir-nokogiri.
tags: code - ruby