Check tag classes with watir?

微笑、不失礼 提交于 2019-12-01 17:45:59
Željko Filipin

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

You can do this with jquery (or not, jquery sintax is only more simple but with getelement you can do anything).

This is an example that add class with a button click:

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

this work also with $(".classname"). Hope it help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!