Skip to content
This repository has been archived by the owner. It is now read-only.

InternetExplorerDriver cannot find element via XPath containing name attribute #2453

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

Comments

Projects
None yet
1 participant
@lukeis
Copy link
Member

commented Mar 3, 2016

Originally reported on Google Code with ID 2453

What steps will reproduce the problem?
1.  Create a file sample.html in a server's document root:

<html>
    <body>
        <span name="foo">bar</span>
    </body>
</html>

2.  Using InternetExplorerDriver as driver, run:

driver.navigate().to("http://localhost/sample.html");
driver.findElement(By.xpath("//span[@name='foo']"));

What is the expected output? What do you see instead?
This test should pass.  Instead, it throws NoSuchElementException.  This does not happen
with FirefoxDriver.

Selenium version:
OS: Windows 7
Browser: Internet Explorer
Brower version: 9

Reported by jqp.code on 2011-09-13 14:35:03

@lukeis lukeis self-assigned this Mar 3, 2016

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

I'm seeing this on Selenium 2.5.0 for Java.

Reported by jqp.code on 2011-09-13 14:43:30

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

maybe, try to wait a few second before the page is fully loaded.
I've encountered this several times.

The temporary solution should be just do By.name("foo")

In IE, actually most @something='' XPath just doesn't work well

Reported by ypwalter on 2011-09-13 17:12:37

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

This is also present in Selenium 2.6.0 for Java.

Regarding Comment 2: the page was fully loaded when findElement() was executed.  Also,
in this case, By.name("foo") won't completely do the job, because the test also needs
to verify that the element is a span.

Reported by jqp.code on 2011-09-14 17:13:01

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

My investigation of #2453 shows that IE can find //XXX[@name='foo'] if only XXX has
an attribute name specified in HTML standard (form, a, img etc.)

I don't know whether it is correct or not, just FYI.

Reported by barancev on 2011-09-16 21:36:51

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

Reported by barancev on 2011-10-04 09:22:13

  • Labels added: Component-WebDriver, Browser-IE
@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

I have the same problem with locator like //td[contains(text(), 'aa')]
With help of IE debug log i figure out that source of problem is in in Javascript-Xpath
library which is used as atom for Xpath queries in IE and located in Generated/jsxpath.h.

Also i checked that the same locator is worked if last 0.1.12 version of this library
is loaded by the following actions:
* stop test before it fails
* run js console
* load and execute full source of library from http://svn.coderepos.org/share/lang/javascript/javascript-xpath/trunk/release/javascript-xpath-latest.js
* execute code example with my xpath locator
-> it works!
(as i see it was fixed at 0.1.9 version).

After that i tried to update this atom but:
0. it looks like an atom but have another format of .h file
1. it has no direct source in selenium code. there is \javascript\selenium-core\xpath\javascript-xpath-0.1.11.js
file which is not used as source for this .h file. Looks like .h and .js files both
were created and maintained paralelly.
2. there are at least one difference b/w sources - in jsxpath.h method "__webdriver_evaluate"
exists but in javascript-xpath-0.1.11.js and lastest javascript-xpath code it doesn't.

So i'd like to implement normal build, removing duplicates, update library to latest
version and maybe mechanism to enable different js xpath implementatons (at build,
execution or something else level). 
For these I need for some knowledge transfer - about current solution, about possible
ways of switching b/w js xpath implementations etc, i think ?
Or i can implement own solution and just send patch ?

Could somebody clarify these?

Reported by a.u.savchuk on 2012-07-02 06:09:07

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

Simple page at which Xpath query is executed is attached.

Executed xpaths are "//td[contains(text(), 'mMm')]", "//td[contains(@style, 'solid')]",
"//td[contains(@style, 'SOLID')]".

RemoteWebdriver via IE9 at grid and local InternetExplorerDriver IE8 are tested.

Configurations:
* Win7 + IE8
* Vista + IE9

Reported by a.u.savchuk on 2012-07-02 11:02:18


- _Attachment: [page.htm](https://storage.googleapis.com/google-code-attachments/selenium/issue-2453/comment-7/page.htm)_
@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

I used the attached page, and manually performed the following steps:

1. Loaded the page into IE9 and opened the Script tab in the F12 developer tools
2. Copied the latest compressed version of the JavaScript from http://svn.coderepos.org/share/lang/javascript/javascript-xpath/trunk/release/javascript-xpath-latest.js,
pasted into the script tab, and clicked "Run script"
3. Entered the following line into the script tab and executed it:

    document.evaluate("//td[contains[text(), 'mMm')]", document, null, 7, null)

I received a node list result, but one that contained no elements. This tells me that
the problem is in the JS Xpath engine itself, not the IE driver per se. What did I
do differently from you that you were able to get a successful result from the raw
JavaScript?

Reported by james.h.evans.jr on 2012-07-02 13:59:39

  • Status changed: NeedsClarification
@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

Hi,

I made mistake, sorry.
I tried xpath as //td[contains(@style, 'solid')] and after it worked at IE8 configuration
i supposed that it happened due usage of last version of this JS library w/o verifying.
But real reason is IE version change. Sorry again.

But it doesn't change my suggestion to update library, its build procedure
and implementing possibility to replace used implementation of js xpath.

Also, about issue initial issue xpath like //span[@name="abc"].
The source of the problem is optimization made in library (see 4. below)
which prevent access by [@name='abc'] to all elements except such as form, input.
Access by [@id='xyz'] works w/o problems. And [contains(@name, 'abc')] works too.

Some interesting info about this library:
1. it can load own configuration from parameters of src attribute of last script tag.
This may leads to strange behaviour in (very rare) situation, as example, when src
contains targetFrame parameter with correct id of existing iframe. Using this lib will
be installed in  frame and document.evaluate() will not be available.
2. 'text()' is not supported (but something like //td[contains(., string)] can be used)
3. getAttribute() method is mostly used for accessing to attribute values (defined
via @ or attribute::) except predefined list like:
        name: 'name',
        'class': 'className',
        dir: 'dir',
        id: 'id',
        title: 'title'
This method has many limitations (accessing to @style, another non standart attributes,
mixing attributes and properties etc).
4. Some optimizations for cases [@id="<str>"], [@name="<str>"] are implemented on basis
of document.all.item() and document.all.tags() which have limitation - "The name property
only applies to some elements such as form elements".

Reported by a.u.savchuk on 2012-07-05 01:36:27

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

Confirmed. The JavaScript-XPath library is depending on the "all" collection in IE,
which doesn't work in certain cases. Hopefully this will be fixed in a later release.

Reported by zhoumotongxue008 on 2012-07-11 14:16:30

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

We've moded to a new implementation wgxpath, is this issue still actual?

Reported by barancev on 2013-05-19 17:17:44

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

Closing due to inactivity. Please ask to reopen if the issue is still actual.

Reported by a.u.savchuk on 2013-08-15 19:30:37

  • Status changed: Fixed
@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

Hi,

This issue happens in my test cases where the xpath locator of command (cilck) is //div[@class='status-personalized'
and contains(@style,'visibility: visible; display: block;')]. 

I've confirmed that this element exists with Firefox and Selenium IDE.

Could anyone please help to take a look?

Thanks,


Reported by cfnjucs on 2013-10-17 07:57:23

@lukeis

This comment has been minimized.

Copy link
Member Author

commented Mar 3, 2016

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

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this 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.
You can’t perform that action at this time.