How to write css for element containing specific text? - css

I've an element with text List which I want to use. I can write xpath like -
//li[text()='List']
but instead of using xpath, I want to use css. How should I write css for it? I tried with following by referring https://saucelabs.com/resources/selenium/css-selectors but didn't work.
li:contains('List')

The CSS feature :contains('some text') is deprecated, you should only use xpath in your case. There is no way to do that using CSS

Related

why cssSelector in selenium unable to identify the text

I wanna know if i can identify the element based on text of the element, div or link using css only. Is that possible? Because i am not able to use contains method for cssselector.
Please provide the css selector syntax for the below html.
Ex- "Hi There"
No.
You can use XPATH to do it.

CSS Selector equivalent of XPath

What is the CSS selector equivalent of XPath "//a[contains(text(),'Next ยป')]"?
Thanks
You cannot find text with CSS directly, you could set CSS properties via JavaScript based on the internal contents but in the end you would still need to be operating in the definitions of CSS.

CSS3 Selectors - style hashtag-words

I've searched a lot, but still cant find a way to use CSS3 Selectors to style all words starting with a #... Like #diy. Shouldnt that be possible using css-only?
Selectors aren't designed for selecting text content directly in part or in full, so no, it shouldn't.
Selectors are designed for matching elements. If you want to style hashtags differently, you should be wrapping them in their own elements and then styling those elements.
No, but it can quite easily be done with JavaScript.
Using Extend jQuery.highlight to highlight regular expressions:
$('body').highlight(/\B#\w+/)
Working example: http://jsfiddle.net/kobi/ttd9r/

selenium - how to click on a link based on its text using css instead of xpath and without using the contains operator?

I try to use css locators over xpath when I can.
I have the following xpath locator that I would like to change to css:
//table[#id='service_schedule_sets']//a[text()='OptimalTest']
I would like to use a css locator. I wish to avoid using contains as there are support issues in later versions of css (i.e. contains was removed from css2 and css3 (css2 removal was a very last minute thing) that selenium covers up but I would like to avoid.
I am trying:
css=table#service_schedule_sets a[.='OptimalTest')
but it doesn't find the element.
The HTML is:
<td>
OptimalTest
</td>
Notes:
I want to use the text in the link ('OptimalTest') not the href.
I do not want to use link=OptimalTest approach as it is not specific enough.
CSS selectors do not support node selection based on their text content.
Actually there was a suggestion for a pseudo class :contains which would suit your needs, but it was removed from CSS 3 spec.

Locating tag by its text using css

How would you get the following tag using CSS?
<p>You can only use the text inside the tag</p>
As in xpath I'd use the following:
//p[contains(text(), "inside the tag")
PS: I can't close the xpath, it tries to auto complete with code... :S
I believe CSS3 selectors can only filter attributes, not the text within tags. So you could do something like a[href~="aspx"] to match links to aspx pages, but that's as far as content-based matching can go.
For what you want to do, you'll probably have to use javascript or server-side processing.
Have a look at quirksmode and W3 for more information.
This is what I was looking for!
p:contains("inside the tag")

Resources