support "data_bar: false" feature from watir version 6.3
Closed this issue · 5 comments
Apropos of http://watir.github.io/watir-6-3/ and the feature "Locate elements based on presence/absence of an attribute", it would be great to support this, I could use this right away.
It is not clear to me what the syntax inside a Page Object would be.
maybe PR ;) ?
Page Object just passes the specified locators to Watir (aside from some handling of frames). As a result, Page Object already supports the presence/absence locators.
The syntax is the same as with any other locator. For example, the below page object uses the presence/absence in both accessors and nested element calls.
class TestPage
include PageObject
span(:with, data_bar: true)
span(:without, data_bar: false)
def blah
p span_element(data_bar: true).text
p span_element(data_bar: false).text
end
end
I'm not sure about that. Maybe I misunderstand.
For example, let's say I have two elements
list_item(:one_label, class: 'busy backson')
list_item(:two_label, class: 'busy')
How would I distinguish :two_label?
I tried
list_item(:two_label, class: 'busy', backson:false)
but that returns an error "invalid attribute: :backson (Watir::Exception::MissingWayOfFindingObjectException)
I think you're misunderstanding the Watir feature. The feature is for detecting whether an attribute has been specified or not on the element. For example:
list_item(:one_label, class: true) #=> would match <li class="something"> but not <li>
list_item(:two_label, class: false) #=> would match <li> but not <li class="something">
In your example, "backson" is part of the class attribute value rather than an attribute itself. Locating elements that do not have a specific class are a bit tricky. I find the best approach is to use a CSS-selector:
list_item(:one_label, css: 'li.busy.backson') # class has "busy" and "backson"
list_item(:two_label, css: 'li.busy:not(.backson)') # class has "busy" but does not have "backson"
It sounds like this isn't an issue with page-object. And thanks to @titusfortner, there's even more convenient ways to approach the problem. I'm closing this for now. @chrismcmahon, feel free to reopen if there's still an issue.