[webdriver] how to do an exact match for the inner text via css selector

2,064 views
Skip to first unread message

shen xieyin

unread,
Aug 2, 2011, 10:18:36 PM8/2/11
to webdriver
we can use the syntax css=a:contains(“Inner Text”) to a text match to find the element, but it seems not to be a exact match, if I have the text "Inner Text a" "Inner Text b" "Inner Text", it will just return the 1st one. So if I want to keep the css selector for the locator type, how can I deal with that, can we do an exact match?


Thanks,
-Shen

Jim Evans

unread,
Aug 3, 2011, 2:15:15 AM8/3/11
to webdriver
Please realize that the :contains pseudoclass is not part of the CSS
selectors standard, but is an extension provided by the Sizzle library
(Sizzle is the JavaScript CSS selector engine used by jQuery).
The :contains() selector will not work on all browsers unless you
first inject Sizzle. You'd be better off asking that question of the
jQuery folks.

--Jim

shen xieyin

unread,
Aug 3, 2011, 3:55:15 AM8/3/11
to webd...@googlegroups.com
oh, i did not realize that. thanks for pointing that out. My case is we have many case with selenium1 calling select(locator, option), in this method it just needs to pass a locator of the select, and then give the option label/value/index. but in selelnium2, which directly call By.cssSelector(), so here we need do a transparent way to generate all the full string of css-selector such as //select[name='abc'] option[value='ccc'], for the new API.

any idea?

2011/8/3 Jim Evans <james.h....@gmail.com>
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Daniel Wagner-Hall

unread,
Aug 3, 2011, 6:45:51 AM8/3/11
to webd...@googlegroups.com
If you're hoping for a:contains, investigate the By.linkText and
By.partialLinkText locators

If you're hoping trying to manipulate Select elements and Options in
them, look at the Select support class:
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/Select.html

Reply all
Reply to author
Forward
0 new messages