user1403776
user1403776

Reputation: 21

How I can access elements via a non-standard html property?

I'm try to implement test automation with watir-webdriver. By the way I am a freshman with watir-webdriver, ruby and co.

All our HTML-entities have a unique HTML-property named "wicketpath". It is possible to access the element with "name", "id" a.s.o, but not with the property "wicketpath". So I tried it with XPATH but I have no success.

Can anybody help me with a codesnippet how I can access the element via the propertie "wicketpath"?

Thanks in advance.

R.

Upvotes: 2

Views: 354

Answers (2)

Justin Ko
Justin Ko

Reputation: 46836

You should be able to use xpath.

For example, consider the following HTML

<ul class="ui-autocomplete" role="listbox">
    <li class="ui-menu-item" role="menuitem" wicketpath="false">Value 1</li>
    <li class="ui-menu-item" role="menuitem" wicketpath="false">Value 2</li>
    <li class="ui-menu-item" role="menuitem" wicketpath="true">Value 3</li>
</ul>

The following xpath will give the text of the li that has wicketpath = true:

puts browser.li(:xpath, "//li[@wicketpath='true']").text
#=>Value 3

Update - Alternative solution - Adding To Locators:

If you use a lot of wicketpath, you could add it to the locators.

After you require watir-webdriver, add this:

# This allows using :wicketpath in locators
Watir::HTMLElement.attributes << :wicketpath

# This allows accessing the wicketpath attribute
class Watir::Element
  attribute(String, :wicketpath, 'wicketpath')
end

This will let you use 'wicketpath' as a locator:

p browser.li(:wicketpath, 'true').text
#=> "Value 3"

p browser.li(:text, 'Value 3').wicketpath
#=> true

Upvotes: 2

user3487861
user3487861

Reputation: 350

Try this

puts browser.li(:css, ".ui-autocomplete > .ui-menu-item[wicketpath='true']").text

Please Let me know is the above scripting is working or not.

Upvotes: 0

Related Questions