Reputation: 11
Using Watir Webdriver, I wanted to have a helper that would check for any element with given id. I may not know what type it is ( button or link or text). Can I just do
browser.Element(:id, id).exists
All of the examples i've found on google check against a specific element type, as in
browser.button(:id," ").exits
If there is a way, please share the syntax.
Upvotes: 1
Views: 217
Reputation: 508
I've never gotten .exists? to work right on it's own.
What I've had to use in these cases has been to explicitly validate the "exist?"... like:
cf_checbox = @browser.text_field(:id=>'continue-ring', :value=>true).exists?
assert( cf_description == true)
without that explicit assertion, I would always get a "true" even when the value didn't exist.
Upvotes: 0
Reputation: 57312
As Dave points out, there is #element
method. (You were wrong just in capitalization, it is not #Element
.)
Since you are asking about accessing it using id
attribute, try this:
browser.element(:id => id)
Upvotes: 0
Reputation: 2016
In Watir-Webdriver, I would use something like this:
browser.element(class: 'post-tag').exists?
which would find the watir-webdriver tag on this page and report that it exists. Note that I used the 1.9 syntax instead of the alternative syntaxes of:
browser.element(:class => 'post-tag').exists?
or
browser.element(:class, 'post-tag').exists?
Upvotes: 2