Reputation: 266
I have an element with the following styles
<ul class="textboxlist-bits" style="background-color: transparent;">
Now I want to select the element based on the style attribute.
The css selector ul [style="background-color: transparent;"]
does not work there.
Kindly suggest an appropriate selector to identify such element.
Upvotes: 4
Views: 16133
Reputation: 151
A possible solution is to select all elements with matching class name, then the first of those with the correct style attribute. You haven't said which language the test is written in, but an example in C# would be:
IWebElement element = driver.FindElements(By.CssSelector("ul.textboxlist-bits")).First(e => e.GetAttribute("style").Contains("background-color: transparent;"));
Upvotes: 1
Reputation: 16115
I think you only have to remove the first space:
ul[style="background-color: transparent;"]
Now it is searching all ul
-tags which have this style; with the space between it tries to select all dom elements in(!) a ul
-tag which have this sytle.
Here an example with the querySelector for javascript, it should work with selenium too.
Upvotes: 6
Reputation: 129
Maybe this http://reference.sitepoint.com/css/elementtypeselector not sure if you mean something like an if statement in c?
[ { attribute | attribute { = | |= | ~= } attribute value } ] {
declare stuff here..
}
or
this matches any type input that matches 'submit'
input[type="submit"] {
declarations
}
Upvotes: -1