Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

CSS Selectors defective in IE 8/9 #4074

Closed
lukeis opened this issue Mar 3, 2016 · 7 comments
Closed

CSS Selectors defective in IE 8/9 #4074

lukeis opened this issue Mar 3, 2016 · 7 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 4074

What steps will reproduce the problem?
1. Navigate to webpage
2. Select element using: tab = driver.find_element_by_css_selector('ul.tabs:eq(1) li:nth-child(1)
a') 

What is the expected output? What do you see instead?
The element should be selected. Instead, it throws a WebDriverException saying it cannot
find the element.

Selenium version: 2.23 server with IEDriverServer 2.23 32-bit
OS: Windows 7
Browser: IE
Browser version: 8,9

To clarify, this code works on the same page with IE 7. Also, using the dev tools in
IE 9 (while IE 9 is running through selenium as a proxy, so in the same conditions
as in the testcase), I can access the element fine using the Javascript console (i.e
by $('ul.tabs:eq(1) li:nth-child(1) a')) 

This is the chunk of code the selector is part of:
for x in xrange(1,11):
    try:
        tab = driver.find_element_by_css_selector('ul.tabs:eq(1) li:nth-child(%d) a' % x)

    except NoSuchElementException, WebDriverException:
        tab = None

    if tab: 
        tab.click()
        path = self.urlToPath(driver.current_url)
        self.screenshot_and_checkJS(path, '_tab%d' % x)


Here's a JSBin of the page that exhibits the bug: http://jsbin.com/udohal/7/ (I stripped
down the real page to get that, but it exhibits the same issue). 

Reported by ankitsoni9 on 2012-06-12 15:18:09

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Forgot to mention:
1. The exception is thrown on the line tab = driver.find_element_by... , when x=1
2. Using latest jQuery version on the jsbin doesn't help
3. Why doesn't the code catch the WebDriverException instead of terminating with it
anyways?

Reported by ankitsoni9 on 2012-06-12 15:25:50

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

More updates: Surprisingly, the ":eq" selector doesnt seem to be causing a problem,
its the ":nth-child". If I remove that, it works fine.

Reported by ankitsoni9 on 2012-06-12 15:40:39

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Seems this is an issue with Sizzle, but could anyone suggest a workaround that works
with IE 8?
For IE 9 im using:
tab = driver.find_element_by_css_selector('ul.tabs:nth-of-type(1) li:nth-of-type(%d)'
% x) 
and for IE 7:
tab = driver.find_element_by_css_selector('ul.tabs:eq(1) li:nth-child(%d)' % x)

but IE 8 doesn't seem to like any use of nth-of-type, nth-child or :eq

Reported by ankitsoni9 on 2012-06-12 16:28:50

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

For browsers that support CSS selectors natively[1], we use the browser's native CSS
selector engine. If it's not supported, we inject and use Sizzle. This means that for
IE 6 and 7, you get Sizzle selectors, which do may comply with the CSS selector standards.
For IE 8 and 9, you're stuck with the CSS selector support of IE 8, which doesn't support
any of the CSS3 selectors.

[1] "Support" in this context means "implements document.querySelector()".

Reported by james.h.evans.jr on 2012-06-12 19:13:45

  • Status changed: WontFix

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Is there a way to force Selenium to use Sizzle on IE 8 and 9?

Reported by ankitsoni9 on 2012-06-13 12:54:47

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

No, and that's not a feature that's likely to ever be added. If the page you're testing
is already using jQuery, you can use JavaScript via execute_script() to find the element
you're looking for. If it doesn't, you can inject Sizzle into the page yourself using
execute_script()

Reported by james.h.evans.jr on 2012-06-13 14:42:14

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:15:39

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant