Check Tag Classes with Watir

Check tag classes with watir?

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

how to get class of an element in ruby / watir?

This should do it:

browser.ths(:class => "disabledHeader").size

How to use watir-webdriver to find element by class and text

After the updates, if you're looking for the cell with test 2 and without class test2, you should use this regex on the class:

b.td(:class => /^((?!test2).)*$/, :text => "2").click

UPDATE:

To require matching test1 but omitting test2, I updated the regex:

b.td(:class => /^((?!test2).)*test1((?!test2).)*$/, :text => "2").click

how to check class of anchor tag on the basis of its id in watir?

Is this what you need?

browser.a(:id => "tab_Companies").class_name
# => "disabled"

How can I have watir recognize an input tag with a custom class?

Summary page at Watir wiki links to a few pages with a lot of useful data. Take a look at How and What, HTML Elements Supported by Watir and Ways Available To Identify HTML Element.

Examples (tested on Mac OS 10.6 with firewatir 1.6.6.rc1):

browser.text_field(:id => "Projects-Projects_Project_0_Task_0_EntryHours_0").set "test"
browser.text_field(:id => /Project_0/).set "test"
browser.text_field(:class => "input-time").set "test"

How to find element by watir-webdriver using more than one class?

In this case, use a CSS selector directly:

browser.div(css: '.first_class.second_class')

Note that the "by class" locator is actually transformed to a "by CSS selector" under the hood.

Watir not finding all elements with a class name

likes = @browser.spans(:class => "className")

This one clearly wouldn't work because you are speaking like class name contains "className" so you better write with regular expression

likes = @browser.spans(:class => /className/)

Or go with your other option with a little correction since you only want span, you don't have to use * instead use span

likes = @browser.elements(:xpath, "//span[contains(@class, 'className')]")

Watir usually wait until page loads completely when you are navigating one page to another, we don't have to use any static sleep statement but Since you say page loads more span when get to the bottom your case seems to be little different ,I strongly suspect the above code executes quickly even before page loads completely so put sleep 5 to check whether you get increase in number of spans, so write the following code with sleep 5

WATIR has the execute_script for you, so you don't have to use selenium execute_script directly

@browser.execute_script("window.scrollBy(0,document.body.scrollHeight)")
sleep 5
likes = @browser.elements(:xpath, "//span[contains(@class, 'className')]")

How to access the body tags using watir

The above it has iframe element try as

@ie.iframe(:id,':13r').body(:id,':13r').set 'sample'

Ruby Watir Webdriver - How to identify and click on the element in div tag?

It's inside the link, div is the parent of that link,

So write this code

b.element(link: 'Sign Up with Email').click

Or

b.link(text: 'Sign Up with Email').click

It would work.



Related Topics



Leave a reply



Submit