I have a bunch of li
elements. They are either with uncompleted
, 'current' or completed
class or without a class.
How do I find all li
elements without completed
class?
So far I am doing this by selecting necessary li
objects from collection of li
(through calling #attribute_value('class')
, but maybe there is some elegant locating strategy in Watir-WebDriver?
UPD: As long as there is some misunderstanding of the question.
I want to know if there is locating strategy within Watir-WebDriver to find elements which class is not completed
.
I know I can do this with Ruby and doing it like this:
browser.lis.select do |li|
li.attribute_value('class') != 'completed'
end
But the question is if I can do this in one line by passing some argument to #lis
UPD2: Just realized that given class names narrows solutions. Updated question and sorry for that.
In order to not assume that there are only two classes of arrays, you can do:
or even:
The LI collection supports locators, which means you can do:
UPDATE: For the case where there are multiple classes, you can modify the above to use a regex to check for not completed:
This returns all
li
that have no class or are not exactly 'completed' (ex 'completed2').Note: I think
.class_name
may have better support thanattribute_value('class')
(which I believe does not work in IE as it needs to be className).