Selenio: localizadores CSS de IE8

I'm using selenium with IE 7,8,9 and for some reason, some CSS 3 locators are working in IE 7 and 9, but not 8. This is the code for the locators:

IE 9

tab = driver.find_element_by_css_selector('ul.tabs:nth-of-type(1) li:nth-of-type(%d)' % x)

IE 7

tab = driver.find_element_by_css_selector('ul.tabs:eq(1) li:nth-child(%d)' % x)

but in IE 8, using the nth-child, or :eq, or nth-of-type locator yields a WebDriverException saying it can't find the element.

Also, the code above works on IE 8 through the dev console, it just doesn't work with selenium (presumably because selenium uses Sizzle for selectors).

Could anyone enlighten me as to why this doesn't work on IE 8, or suggest possible workarounds that would work. (I've tried stuff like ul.tabs:eq(1) > li:nth-child(%d) i.e inserting >s between the selectors, but that didn't work)

I'm using selenium server 2.23, with IEDriverServer 32-bit and the python 2.23 API.

preguntado el 12 de junio de 12 a las 18:06

"presumably because selenium uses Sizzle for selectors" - Selenium1 uses sizzle not Webdriver/Selenium2. Webdriver uses css selectors. -

1 Respuestas

As @A.J said, Selenium 2 uses the browsers native CSS selectors if they are available. So in this case, it was using Sizzle for IE 7, and native selectors for IE 8 and 9. Obviously, IE 8's selectors were unable to handle things correctly.

The workaround I ended up using was to target the correct ul.tabs by descendant selectors and then to use the + selector and jQuery's next() method to traverse the list.

Respondido el 13 de junio de 12 a las 16:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.