views:

350

answers:

3

Does anyone know why this CSS selector works in Firefox but not in IE7 or IE8?

css=div[style~='visible;'] div[class~='x-combo-list-item']:contains('Test Job')

I'm using this in a Selenium test to find an element on the page.

Edit: The :contains selector is not the problem. I'm using it elsewhere in my tests and it works in IE6, 7, and 8.

A: 

Probably because the :contains pseduo-class is a CSS3 addition and whatever version of IE you're using (you didn't specify) probably doesn't support :contains.

http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#selectors

theraccoonbear
Thanks for the suggestion, but I'm using :contains in a number of different places, and IE7 and IE8 both support it.
Mark Erdmann
+1  A: 

I know that Selenium attempts to support all of CSS3 for all browsers in it's selector engine. It may be that it does not support multiple levels of the attribute selectors in IE.

You might be stuck with an XPath "locator" this one

Alternatively, you could try:

div[style~='visible'] .x-combo-list-item:contains('Test Job')
Eric Wendelin
I'll look into that, thanks. Do you know if Xpath supports something similar to "~="?
Mark Erdmann
Yes, //div@style[contains('text')//div@class[contains('..')]
Eric Wendelin
Argh, wish I could edit comments. Last one should be://div[contains(@style,'text')]...
Eric Wendelin
Awesome, thanks for your help.
Mark Erdmann
Word of warning, though, XPath is sloooow on IE when you use "//" queries.
Eric Wendelin
For the sake of posterity: the XPath did the trick. I tried the modified CSS selector, but for whatever reason Selenium doesn't like ".class".The working XPath version of my CSS: //div[contains(@style, 'visible')]//div[contains(text(),'Test Job')]
Mark Erdmann
Yeah... I've definitely experienced the slowness, which is why I'm using CSS selectors wherever possible.
Mark Erdmann
That's what I reasoned ;)
Eric Wendelin