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
Table is located using locator property “tagname”. Using XPath “//*[@id=\”leftcontainer\”]/table/tbody/tr[3]” find the 3rd row and gets its text using getText () function. Using Xpath “//*[@id=\”leftcontainer\”]/table/tbody/tr[3]/td[2]” find the 2nd cell in 3rd row and gets its text using getText () function.
To check broken links in Selenium, the process is simple. On a web page, hyperlinks are implemented using the HTML Anchor (<a>) tag. All the script needs to do is to locate every anchor tag on a web page, get the corresponding URLs, and run through the links to check if any of them are broken.
Let's select an element in the web table and find its XPath. For Chrome, right-click and inspect the given element to find its XPath. To find the XPath of a UI element in Firefox, right-click on the desired element, go to “Inspect Element” to open the inspector which will help identify its XPath.
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/">Batman</a></td></tr>
</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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With