.

watir cool stuff

Instead of looping over the elements like this:

browser.links.each do |link|
  link.click
  browser.goto home
end

I have found it’s better to collect the hrefs of each, and use these collected values:

links = browser.links.collect { |link| link.href }
links.each do |link|
  browser.goto link
  browser.goto home
end

Instead of looping through a element collection to find some element value:

def error_exists? text
  errors = browser.spans(:class => 'error').collect
 
  errors.each do |span|
    return true if span.text == text
  end
  false
end

I have found it is better to directly find the element itself

def error_exists? text
  browser.span(:class => 'error', :text => text).when_present.exists?

end

What's your thoughts on this?

*

Protected by WP Anti Spam