[webdriver]By.cssSelector question

824 views
Skip to first unread message

Nilesh

unread,
Jan 31, 2011, 11:39:46 AM1/31/11
to webdriver
I am trying to replace an xpath with css selector. For example for
below html code, I have something like,
By.xpath(".//div[contains(text(), '1 - 15 of 82')]")
I want to replace this with
By.cssSelector("div:contains('1 - 15 of 82')"). However this is not
working.

If I try By.cssSelector("div#tblCampaign_paginate>span>div")- it works
but I want to use 'contains' in the css selector somehow. What am I
doing wrong?

I am using 2.0a7, Windows XP and Java.

Thanks,
-Nilesh

<div class="dataTables_paginate" id="tblCampaign_paginate">
<span class="prevGridFirst " id="tblCampaign_first">&nbsp;</span>
<span class="prevGrid " id="tblCampaign_previous">&nbsp;</span>
<span>
<div style="padding-right: 6px;"> 1 - 15 of 82 </div>
</span>
<span class="nextGrid DisabledNav" id="tblCampaign_next">&nbsp;</
span>
<span class="nextGridLast DisabledNav" id="tblCampaign_last">&nbsp;</
span>
</div>

Exception for Firefox:
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_19'
Driver info: driver.version: remote
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:
131)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:
105)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
352)
at
org.openqa.selenium.firefox.FirefoxDriver.execute(FirefoxDriver.java:
237)
at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:
170)
at
org.openqa.selenium.firefox.FirefoxDriver.findElementByCssSelector(FirefoxDriver.java:
211)
at org.openqa.selenium.By$8.findElement(By.java:280)
at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:
166)

Caused by: org.openqa.selenium.remote.ErrorHandler
$UnknownServerException: 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_19'
Driver info: driver.version: unknown

Daniel Wagner-Hall

unread,
Jan 31, 2011, 12:22:44 PM1/31/11
to webd...@googlegroups.com
:contains was removed from the CSS3 spec [1], which is only a draft,
and wasn't present in the CSS2 spec.

We delegate to the underlying browsers' CSS selector implementation
(and happen to fake in the behaviour in IE, which doesn't support CSS
selectors), so cannot make any promises about supporting particular
selectors. You can be fairly sure that CSS2 is supported everywhere,
though.

1:http://www.w3.org/TR/css3-selectors/#content-selectors

> --
> 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.
>
>

Nilesh

unread,
Feb 1, 2011, 1:12:31 PM2/1/11
to webdriver
Thanks Daniel. I didn't know that webdriver API fakes CSS selectors in
IE. I was wondering if replacing xpaths by CSS selectors would give me
any speed improvement in IE. Is that a recommended approach in
general?

On Jan 31, 12:22 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
> :contains was removed from the CSS3 spec [1], which is only a draft,
> and wasn't present in the CSS2 spec.
>
> We delegate to the underlying browsers' CSS selector implementation
> (and happen to fake in the behaviour in IE, which doesn't support CSS
> selectors), so cannot make any promises about supporting particular
> selectors.  You can be fairly sure that CSS2 is supported everywhere,
> though.
>
> 1:http://www.w3.org/TR/css3-selectors/#content-selectors
>
Reply all
Reply to author
Forward
0 new messages