Avoid using complex CSS selectors with Selenium. It's tempting to try techniques you're familiar with from jQuery, but they may not be supported in CSS or by the browser version you're using. For example, 'nth' is one such case.
Instead, simplify your selector like this:
css=table#playlistTable tr:first-child span.playlistNumDisplay.smallFont
You can further streamline your selector based on the specific elements you need to match and those that don't overlap with others.
.
Keep in mind that :first-child
is part of CSS 2.1, whereas :nth-child()
and attribute value selectors (like [class='...']
) are features of CSS 3. This means better browser support for the former than the latter.
.
Another helpful tip is using a jQuery locator, which can be included as shown here:
How do I add a JQuery locators to Selenium Remote Control
Keep in mind, this method will only work on pages that support jQuery. We've successfully implemented this approach on a large e-commerce website before.