开发者

css query for selenium

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='playlistNumDi开发者_如何学JAVAsplay smallFont']

what wrong am I doing here? thanks for the help


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜