Ray Cheng
Ray Cheng

Reputation: 12586

Not able to select nth-child with Selenium IE driver

I would like to select the second or nth option from a select element with the IE driver using css selector.

I tried the following but it doesn't work.

option:nth-child(1)

If I provide a value, it works, but I don't know the value all the time so I like to select by nth-child.

option[value='1']

the error i got on IE8 is javascript error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; MS-RTC LM 8; .NET4.0E; Tablet PC 2.0)
Timestamp: Wed, 26 Sep 2012 23:34:46 UTC

Message: Invalid argument.
Line: 30
Char: 96
Code: 0
URI: http://blah/foo.aspx

Upvotes: 1

Views: 778

Answers (1)

JimEvans
JimEvans

Reputation: 27496

This is perfectly expected. Internet Explorer 8 supports querySelector() and querySelectorAll(), so the IE driver relies on the browser's native implementation of CSS selectors, which means you're limited to whatever level of CSS selector support is provided by the browser. In the case of IE 8, the browser does not support CSS3 selectors, so the IE driver will not work with any CSS3 selectors. Of course, nth-child() is part of the CSS3 specification, so using the IE driver with IE 8 will not support nth-child(). As for what selectors are supported by which browsers, there is a great reference at quirksmode.org which provides a nice summary of each of the selectors and which browsers they are supported in.

Upvotes: 1

Related Questions