CSS equivalent of XPath text()

536 views
Skip to first unread message

sunny sachdeva

unread,
Apr 1, 2013, 6:37:10 AM4/1/13
to seleniu...@googlegroups.com
HI,

Wondering how to convert below XPAth to CSS

XPATH:-  //span[text()='Calendar']

I tried span:contains('Calendar') but this throws DOM Exception 12

Let me know how can we write this in CSS.

Thanks
Sunny

Jim Evans

unread,
Apr 1, 2013, 7:34:49 AM4/1/13
to seleniu...@googlegroups.com
Short answer is you can't. The longer and more detailed answer can be found in my reply to you on the WebDriver mailing list.

Arran

unread,
Apr 2, 2013, 4:38:28 AM4/2/13
to seleniu...@googlegroups.com
Why does it need to be done in CSS? There is no contains selector in CSS (in any version), which I suspect is what Jim is referring to above.

Ripon Al Wasim

unread,
Apr 2, 2013, 4:52:03 AM4/2/13
to seleniu...@googlegroups.com
Hello,

The corresponding CSS path is:  span:contains(^Calendar$)

You can follow the steps below for details how to convert xpath into csspath by using  http://cssify.appspot.com/  this site.

2. See my answer at the bottom of page

br,
Ripon
skype: ripon_sky


Sunny

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/8aULtZv8Qu4J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jim Evans

unread,
Apr 2, 2013, 8:47:35 AM4/2/13
to seleniu...@googlegroups.com
tl;dr: The :contains() pseudoselector doesn't exist. If you're using it, stop. If you're thinking of recommending someone else use it, don't.

Ripon, I don't normally call out individuals here, but this is so important that it bears repeating. I'm even going to shout for emphasis. THERE IS NO %*#&$@ :CONTAINS PSEUDOSELECTOR!!! To claim there is shows either a willful ignorance of the CSS selector standard; or a misguided belief that jQuery, and by extension Sizzle, is so ubiquitous that its bastardizations can be used without consideration that they are not, in fact, actually implemented by any browser's native CSS selector engine.

SantoshSarma

unread,
Apr 2, 2013, 9:25:55 AM4/2/13
to seleniu...@googlegroups.com
By injecting Sizzle css selector library you can achieve that

see below post 



Regards,

Jim Evans

unread,
Apr 2, 2013, 9:40:39 AM4/2/13
to seleniu...@googlegroups.com
Injecting Sizzle seems like a very long way to go just to get a pseudoselector that you can already duplicate the functionality of with a simple XPath statement. I rarely recommend XPath over CSS selectors for performance reason; this is my line exception to that rule. But if you're relying on finding the element by its text content, performance is the least of your worries anyway.

Tarun Kumar

unread,
Apr 2, 2013, 2:04:44 PM4/2/13
to seleniu...@googlegroups.com
On a tangential note. How good is it to inject (jquery etc) library to application under test?
Should not test tool be testing application non intrusively?
Reply all
Reply to author
Forward
0 new messages