How to find inner text for CSS locator contains no longer works with CSS3

923 views
Skip to first unread message

Mike Kirby

unread,
Apr 1, 2014, 1:07:03 PM4/1/14
to seleniu...@googlegroups.com
Is there a way to find the inner text using CSS selector since the contains option no longer work with CSS3.

 

 driver.findElement(By.cssSelector("button:contains('Add New Task')")).click(); - does not work. (work for Seleniun IDE)

Tried the following as per Unmesh Gundecha in the Selenium Testing Tools Cookbook - Locating elements using Text section


driver.findElement(By.cssSelector("button[textContent='Add New Task']")).click(); - does not work in IE 10 or Firefox 28


here is the snippet I am working from the button is called "Add New Task".

<button id="taskConfigForm:j_idt59" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left" type="submit" onclick="PrimeFaces.ab({source:'taskConfigForm:j_idt59',update:'manageTaskConfigForm',oncomplete:function(xhr,status,args){PF('manageTaskConfigDialog').show();;}});return false;" name="taskConfigForm:j_idt59" role="button" aria-disabled="false">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-plus"></span>
<span class="ui-button-text ui-c">Add New Task</span>

Thanks!

David

unread,
Apr 3, 2014, 5:33:06 PM4/3/14
to seleniu...@googlegroups.com
:contains() is only supported through Sizzle, jQuery, and like libraries. Sizzle was used by Selenium IDE and RC, but dropped in favor of native browser CSS support in WebDriver/Selenium 2. Hence why you ran into this problem.

Your options are to inject jQuery/Sizzle into your web application (using WebDriver's executeScript() method), then run the findElement calls that use the contains(). Or switch to XPath, which easily supports contains() but with slower performance.
Reply all
Reply to author
Forward
0 new messages