I am trying to use CssSelector to locate an element on my webpage. I am using Firefox driver.
Here is how I am using the locator (I checked that Selenium IDE is able to locate my element with this
[FindsBy(How = How.CssSelector, Using = "label:contains('Version: 2.0.')")]
public IWebElement labelVersion;
But when use this in the C# code and initialize it with
PageFactory.InitElements in my constructor.
I hit this error… (the error itself is pretty clear but I don’t know how to fix it)
Appreciate any inputs.
OPC.Tests.SmokeTest (TestFixtureSetUp): SetUp :
OpenQA.Selenium.InvalidSelectorException : The given selector
css=label:contains(‘Version: 2.0.’) is either invalid or does not
result in a WebElement. The following error occurred: [Exception…
“An invalid or illegal string was specified” code: “12” nsresult:
“0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)” location:
“file:///………./anonymous439571104.webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js
Line: 5811”]
Selenium delegates CSS queries down to the browser. This means that CSS queries need to follow CSS standard.
Unfortunately :contains was removed from the standard a while back. I recommend that you redo your selector with whats available from the spec or use XPATH.
:contains works in Selenium RC because RC uses Sizzle, the selector search library in jQuery if you are wondering why it works in RC and not WebDriver