Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector (id contains part of text)

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.

like image 707
TarasLviv Avatar asked Aug 28 '12 08:08

TarasLviv


People also ask

Can we use text in CSS selector?

The inner texts are the string patterns that the HTML tag manifests on the web page. ':' is used to symbolize contains method. Click on the "Find target in page" button to check whether the defined CSS Selector locates the desired element or not.

How do you select an element with ID part '?

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

How do you use text value in CSS selector?

Step 1: Type “css=input[type='submit']” i.e. the locator value in the target box in the Selenium IDE and click on the Find Button. Notice that the “Sign in” button would be highlighted. Attribute – It is the attribute we want to use to create CSS Selector. It can value, type, name etc.

How do I target my CSS ID?

To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.


2 Answers

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

like image 191
CosminO Avatar answered Oct 21 '22 14:10

CosminO


<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"] {  } 
like image 32
Edicarlos Lopes Avatar answered Oct 21 '22 15:10

Edicarlos Lopes