CSS selector (id contains part of text)

CssCss SelectorsWebdriver

Css Problem Overview


I have a question. I have elements something like this:

<a> element with id = someGenerated Some:Same:0:name

<a> element with id = someGenerated Some:Same:0:surname

<a> element with id = someGenerated Some:Same:1:name

<a> element with id = someGenerated Some:Same:1:surname

I need CSS selector to get names. The problem is that I don't know how to get it. I tried a[id*='Some:Same'] - it returned all <a> elements. After I can get elements which id ends with name. But I don't like this idea. I think that it can be done with some other selector.

Css Solutions


Solution 1 - Css

Try this:

a[id*='Some:Same'][id$='name']

This will get you all a elements with id containing

> Some:Same

and have the id ending in

> name

Solution 2 - Css

<div id='element_123_wrapper_text'>My sample DIV</div>

The Operator ^ - Match elements that starts with given value

div[id^="element_123"] {

}

The Operator $ - Match elements that ends with given value

div[id$="wrapper_text"] {

}

The Operator * - Match elements that have an attribute containing a given value

div[id*="123_wrapper"] {

}

Solution 3 - Css

The only selector I see is a[id$="name"] (all links with id finishing by "name") but it's not as restrictive as it should.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTarasLvivView Question on Stackoverflow
Solution 1 - CssCosminOView Answer on Stackoverflow
Solution 2 - CssEdicarlos LopesView Answer on Stackoverflow
Solution 3 - CssLeBenView Answer on Stackoverflow