cssSelectors & Sizzle

133 views
Skip to first unread message

JohnMc

unread,
May 18, 2011, 8:53:31 PM5/18/11
to webdriver
I understand that when finding by cssSelector, that the Sizzle
JavaScript CSS selector engine is used to locate the element.

My question is can I use sizzle selectors or does it need to be
strictly css selectors that are used.

For example I am trying to do the following:

driver.findElement(By.cssSelector("details.collapsible:contains(\"Server
Side Collapsible - initially collapsed\")"));

In IE I get the error:
Exception in thread "main" org.openqa.selenium.WebDriverException:
Unable to find element with css selector ==
summary.submit:contains("Server Side Collapsible - initially
collapsed") (WARNING: The server did not provide any stacktrace
information)
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_11'

In Firefox I get:
Exception in thread "main" org.openqa.selenium.WebDriverException: An
invalid or illegal string was specified
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_11'

Is the problem, the usage of the :contains() selector, and why do I
get thast error for Firefox

Jari Bakken

unread,
May 18, 2011, 9:01:36 PM5/18/11
to webd...@googlegroups.com
On Thu, May 19, 2011 at 2:53 AM, JohnMc <j.mcgu...@bigpond.com> wrote:
> I understand that when finding by cssSelector, that the Sizzle
> JavaScript CSS selector engine is used to locate the element.
>

No - in WebDriver, Sizzle is only used as a fallback when the native
CSS implementation (i.e. the Selectors API - document.querySelector
etc.) is not available. That means you should avoid any
Sizzle-specific extensions that are not part of the spec - contains()
being a very good example - if you want your tests to work in modern
browsers.

JohnMc

unread,
May 18, 2011, 9:41:29 PM5/18/11
to webdriver
OK thanks Jari.

On May 19, 11:01 am, Jari Bakken <jari.bak...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages