tags:

views:

443

answers:

1

I am writing Selenium script. For a html page include a table, I can not use "css=table tr:nth-child(2) td:nth-child(3) a" to locate the link in the table. Selenium IDE give me the "[error] locator not found".

But use "css=table tr:nth-child(2)", it can locate to the row. So am I mistake for the css locator, I think adding the "td:nth-child(3) a" should work for the link in td , why not?

Edit: I am using firefox 3.0.15

+3  A: 

Given the HTML:

<html>
  <body>
    <table>
      <tr><td>Hello</td><td>World</td></tr>
      <tr><td>I'm</td><td><a href="http://www.example.com/"&gt;Batman&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
    </table>
  </body>
</html>

You can use the following locator for the link in the 2nd column of the 2nd row:

css=tr:nth-child(2) > td:nth-child(2) > a

Update:

After a little bit of research, it seems your original locator should work, but doesn't due to a bug in the cssQuery library used by Selenium (http://jira.openqa.org/browse/SEL-698). My suggestion above works, but it's really only a workaround until the bug is fixed. Unfortunately, considering the cssQuery hasn't been updated for some time I'm not sure how soon this will be addressed.

Dave Hunt
It works, thanks.
zhongshu