0

I am attempting to find a table cell using a CSS selector in Selenium. This is my selector:

//table[@id='prepaymentItemsDataGrid']//tr[@class='tablerowlight']/td[3]

The exception being thrown is:

Driver.FindElementByCssSelector("//table[@id='prepaymentItemsDataGrid']//tr[@class='tablerowlight']/td[3]") threw an exception of type 'OpenQA.Selenium.InvalidSelectorException'

What is wrong with my selector? How do I know what Selenium is complaining about?

I have tried simplifying it to:

//table[@id='prepaymentItemsDataGrid']

which has no effect.

Does Selenium have a different method of executing CSS selectors and how can I check that the selector is valid before trying to run it?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Matt W
  • 11,753
  • 25
  • 118
  • 215

1 Answers1

4

Though you have tried to use FindElementByCssSelector() but the values were of XPath. You can use either of the following Locator Strategies :

  • CssSelector :

    Driver.FindElementByCssSelector("table#prepaymentItemsDataGrid tr.tablerowlight > td:nth-of-type(3)");
    
  • XPath :

    Driver.FindElementXPath("//table[@id='prepaymentItemsDataGrid']//tr[@class='tablerowlight']/td[3]");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Crikey. Thank you! That was a wood for the trees moment. Guess I forgot what ChroPath was outputting. D'oh! – Matt W Apr 09 '18 at 16:42