4

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.

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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;"));

Comments

-1

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
}

2 Comments

i need a css locator to find match ul elements with the given style attribute . this is for use in selenium where I need to click on such an element with that particular style
thanks for the inputs , but this selector is not working with selenium . I tried something like this ul.textboxlist-bits [style] {background-color: transparent;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.