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?

    1 Answer 1

    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]"); 
    1
    • Crikey. Thank you! That was a wood for the trees moment. Guess I forgot what ChroPath was outputting. D'oh!
      – Matt W
      CommentedApr 9, 2018 at 16:42

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.