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.
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.
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.
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.
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.
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
<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"] { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With