Check tag classes with watir?

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

The launch of an element is as follows.

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

If the input is incorrect, add an error class.

<div id="myerrortest" class="input text error"></div>
+5
source share
2 answers

Try the following:

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

Additional Information:

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

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

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

If you use rSpec types, this will be

browser.div((:id => "myerrortest", :class => 'input text').should exist
+10
source

jquery ( , jquery sintax , getelement - ).

:

$(".button").click(function(){  
$("#myerrortest").attr("class",$("#myerrortest").attr("class")+" error");
});

$( ". classname" ). , .

-2

All Articles