Friday, November 8, 2013

Selenium CSS Locator Tips

How to use nth-child?
nth-child can not return you the nth element in a matched set. It only return the elements who are the nth child of their parent nodes.

Why the Descendant selector does not work with nth-child?
It may be a Selenium bug.
This css locator will not work
css=div.application_details tr:nth-child(1) span.label
But the following one works
css=div.application_details tr:nth-child(1)>td span.label

It seems that Selenium gets confused after nth-child is used. We can use a direct child element to make the Selenium back to sane again. :-)

No comments:

Post a Comment