SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

IE CSS Locator img[src...] no longer working in .31 #5376

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 5376

In 2.30 the following code worked in IE, it no longer works in 2.31: locating element
via Css locator using 

Attribute : src
Value: /somepath/image.jpeg

       private WebElement findElementByAttribute(String attribute, String value) {
              WebElement webElement;
              String cssValImg = "img[" + attribute + "^='" + value + "']";
              if (driver.findElements(By.cssSelector(cssValImg)).isEmpty())
                     return null;
              webElement = driver.findElement(By.cssSelector(cssValImg));  
              return webElement;

       }

Using other tags, such as Alt continues to work.

Reported by p.guindon.slater on 2013-03-20 18:28:58

lukeis commented 8 years ago
To make it simple, the following line failed on IE but passed on other browsers

driver.findElement(By.cssSelector("img[src^='/presentation/images/en-CA/various/realtor.gif']")).click();

And ‘alt’ passed:

driver.findElement(By.cssSelector("img[alt^=' REALTORS® Know Real Estate]")).click();

Reported by p.guindon.slater on 2013-03-20 18:41:18

lukeis commented 8 years ago
What version of IE?

Reported by arran.huxtable on 2013-03-20 19:00:52

lukeis commented 8 years ago
IE9

Reported by p.guindon.slater on 2013-03-20 20:12:20

lukeis commented 8 years ago
What exception and error message have you got on this line of code?

Reported by barancev on 2013-03-21 18:46:08

lukeis commented 8 years ago
org.openqa.selenium.NoSuchElementException: Unable to find element with css selector
== img[src^='/presentation/images/en-CA/various/realtor.gif'] (WARNING: The server
did not provide any stacktrace information)
Command duration or timeout: 336 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0',
time: '2013-02-27 13:51:26'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version:
'1.7.0_05'
Session ID: e2297b3b-efe3-4090-a0e8-27b90bf9b5ba
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true,
ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true,
unexpectedAlertBehaviour=dismiss, version=9, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false,
requireWindowFocus=false, allowAsynchronousJavaScript=true, handlesAlerts=true, initialBrowserUrl=,
nativeEvents=true, takesScreenshot=true}]
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
                at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
                at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
                at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
                at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
                at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:396)
                at org.openqa.selenium.By$ByCssSelector.findElement(By.java:406)
                at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
                at com.teksystems.keywords.ElementKeywordsTest.test_click_image(ElementKeywordsTest.java:34)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
                at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
                at org.junit.runners.Suite.runChild(Suite.java:128)
                at org.junit.runners.Suite.runChild(Suite.java:24)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
                at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
                at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Reported by p.guindon.slater on 2013-03-21 19:07:01

lukeis commented 8 years ago
Here is a quick  test - works on FF, Chrome not IE:

       @Test
       public void test_click_image() throws InterruptedException {
              driver.get("http://www.realtor.ca/realtorSearch.aspx");
              wait.waitSeconds(3);
              driver.findElement(By.cssSelector("img[src^='/presentation/images/en-CA/various/realtor.gif']")).click();
       }

Reported by p.guindon.slater on 2013-03-21 19:09:58

lukeis commented 8 years ago
Here's an even quicker test: Open the page in IE, and press the F12 key to open the
F12 Developer Tools. Switch to the Script tab, and type the following into the console:

document.querySelector("img[src^='/presentation/images/en-CA/various/realtor.gif']")

Then press the enter key. One of three things will happen. First, if the document is
in Quirks mode or in a standards mode less than IE8, you'll get "document doesn't support
property or method querySelector". Second, if the document is in a standards mode,
and the IE CSS selector engine can't find the element, you'll receive nothing back.
Finally, if the IE CSS selector engine is able to find the element, you'll receive
a partial listing of the properties of the element.

If you're in the first case, then there may be an issue with Sizzle, which is a a JavaScript
implementation of a CSS selector engine, and it's also used by jQuery. I note, however,
that the version of Sizzle that we use hasn't change in the timeframe you're talking
about.

If you're in the second case, you're out of luck. If IE's native CSS selector engine
can't find it, then the IE driver won't be able to find it.

If you're in the third case, where IE's native CSS selector engine finds the element,
and the IE driver won't, then there's something radically wrong here. Again, I note
that the CSS selector finding code hasn't change between 2.30 and 2.31 of IEDriverServer.exe,
so it would be uncommon for that to have caused an issue like this.

Reported by james.h.evans.jr on 2013-03-22 01:31:36

lukeis commented 8 years ago
Running : document.querySelector("img[src^='/presentation/images/en-CA/various/realtor.gif']")
On IE does return the element correctly.

Reported by p.guindon.slater on 2013-03-25 14:38:59

lukeis commented 8 years ago
Just a small observation...when I load that page in IE9 the page forces IE9 to Quirks
mode. Could this be part of the issue?

Reported by arran.huxtable on 2013-03-25 14:50:07

lukeis commented 8 years ago
I dont think that is the issue as other css selector work, such as img[alt^=' REALTORS®
Know Real Estate]

Reported by p.guindon.slater on 2013-03-25 15:13:14

lukeis commented 8 years ago
This is almost assuredly tied to the document mode that IE renders the document in.
When I perform a manual test on the URL you provided, the site renders in quirks mode
("IE5 quirks mode" on IE 10). That means that document.querySelector doesn't exist
when I run the manual test from the F12 Developer Tools. What document mode does IE
render the site in when you try the manual test?

Since I'm seeing the browser render the page in quirks mode, that means the IE driver
will fall back to using Sizzle. Sizzle, of course is a JavaScript library, and there
may be an issue that Sizzle is using the *property* instead of the *attribute* for
matching. In IE, the src property always returns the full URL, even if the attribute
is specified using a relative URL, and if Sizzle is using the property instead of the
attribute, your selector will fail using the ^= selector, which is the "starts-with"
selector. Note that it would still succeed using $=, which is the "ends-with" selector.

Addressing the point where it seems to work in 2.30, but fails in 2.31, I'd go back
to make sure that the DOCTYPE of the page hasn't changed. Again, when I open the page
you referenced, IE renders it in quirks mode. If that's different for you, then you'll
receive different results even from the manual test.

Reported by james.h.evans.jr on 2013-03-25 21:49:21

lukeis commented 8 years ago
Sounds moe like an Ie Issue, thanks

Reported by p.guindon.slater on 2013-04-02 16:29:40

lukeis commented 8 years ago
Closing after comment 12

Reported by barancev on 2013-05-12 15:20:35

lukeis commented 8 years ago

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