1
css=table#playlistTable tr:nth(0) span[class='playlistNumDisplay smallFont']

I am getting an error in this css above. I want to basically go to the first 'tr' under 'PlaulistTable and then under the first 'tr' I want to select span[class='playlistNumDisplay smallFont']

what wrong am I doing here? thanks for the help

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Sunny
  • 7,444
  • 22
  • 63
  • 104

2 Answers2

0

You probably meant :nth-child(1) or :nth-of-type(1) rather than simply :nth(0) which is invalid CSS.

If you're specifically looking for the first match, you can also use :first-child or :first-of-type rather than the nth-() variants.

Quirksmode has a good list of the available selectors here http://www.quirksmode.org/css/contents.html (along with a browser compatibility chart, though I don't think that will be relevant to you in the context of a Selenium query)

Hope that helps.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • @BoltClock - You're right of course; they start at 1. I've tweaked it to be `(1)` instead of `(0)`. (my guess is he's converted this to CSS from an existing xpath query which would have been zero based) – Spudley Oct 03 '11 at 11:18
  • how come nth-child(0) select nothing? shouldn;t it select the first child of that kind? or you mean counting starts from 1 instead of 0 for nth-child()? – Sunny Oct 03 '11 at 11:31
  • @Sunny: Yes, it starts from 1. – BoltClock Oct 03 '11 at 11:31
  • @Spudley, u mean nth-child would work for any explorer while using Selenium? – Sunny Oct 03 '11 at 11:55
  • 1
    @Sunny - because Selenium uses it's own CSS parser, not the one built into the browser. – Spudley Oct 03 '11 at 12:23
0

Don;t try to play complex CSS with Selenium. You can try something you used to from jQuery, but it doesn't exist in CSS, or at least the current version of CSS supported by the browser you try it on. 'nth' might be on example of this.

So, simplifying it to:

css=table#playlistTable tr:first-child span.playlistNumDisplay.smallFont

You might consider even simplifying it more, according to which parts of the selector you care about matching, and which are not overlapping with other elements.

.

Note that :first-child is CSS 2.1, while :nth-child() and attribute value selectors (as in [class='...']) are CSS 3, meaning more browser support for the first than the others.

.

One thing that helps as well is using a jQuery locator, which can be implemented as in:
How do I add a JQuery locators to Selenium Remote Control
Of course will be limited to pages supporting jQuery. BTW, we have been using this exact one in a very large e-commerce website pretty successfully.

Community
  • 1
  • 1
Meligy
  • 35,654
  • 11
  • 85
  • 109
  • Attribute value selectors were introduced in CSS 2.1. Only the attribute value substring selectors are new in CSS 3. – BoltClock Oct 03 '11 at 11:32