Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check tag classes with watir?

I have a div that changes based on if the form was submitted correctly or not.
I wanted to know if it's possible to check a specific element for a class or not?

Starting out the element looks like this.

<div id="myerrortest" class="input text"></div>

If the input isn't correct add the error class.

<div id="myerrortest" class="input text error"></div>
like image 202
krizzo Avatar asked May 29 '12 22:05

krizzo


1 Answers

Try this:

browser.div(:id => "myerrortest").class_name

More information:

http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method

Another alternative would be to just see if the div with class you expect exists or not

browser.div((:id => "myerrortest", :class => 'input text').exists?

If using rSpec type matchers it would be

browser.div((:id => "myerrortest", :class => 'input text').should exist
like image 200
Željko Filipin Avatar answered Oct 15 '22 04:10

Željko Filipin