Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chaining element selector will not match deep descendants #1465

Closed
scags9876 opened this issue Jul 18, 2016 · 4 comments
Closed

chaining element selector will not match deep descendants #1465

scags9876 opened this issue Jul 18, 2016 · 4 comments
Labels
Needs Investigation Issues that require more information on the problem.

Comments

@scags9876
Copy link

The problem

Chaining a selector will fail if the element is not an immediate descendant of the base element. It should search the entire descendant tree of the base element.

Environment

Details

With the fix to #1354 a change was made to the findStrategy of chained elements to use the 'relative' flag. While this fixed the issue, it uncovered the fact for us that the relative selection only selects immediate children, and not deep descendants.

There should be an easy for this: changing lib/helpers/findElementStrategy.js:8 to:

    let xpathPrefix = relative ? './/' : '//'

That is, changing the relative xpathPrefix to .// from ./

Link to Selenium/WebdriverIO logs

https://gist.github.com/scags9876/ba6e4eb23da25d58cfa17cd3d9e02830

Code To Reproduce Issue [ Good To Have ]

Does not work

Looking for a label which is inside a containing div in the parent div. This results in an error:

webdriverio
    .remote(options)
    .init()
    .url('http://output.jsbin.com/topaku/1')
    .element('#topdiv')
    .element('label=Took')
    .click()
    .end();
@scags9876
Copy link
Author

It looks to me like this issue has the same root cause:

#1415

@christian-bromann
Copy link
Member

@scags9876 looking at the logs the xpath looks about right:

Executing: [find child element: 0 [[FirefoxDriver: firefox on MAC (b124c848-afb0-a844-bbcf-0e62cdbb596b)] -> id: topdiv], By.xpath: ./label[normalize-space() = "Took"]])

This should find the label inside the topdiv element:

<div id="topdib">
    <label>Took</label>
</div>

@christian-bromann christian-bromann added the Needs Investigation Issues that require more information on the problem. label Jul 20, 2016
@scags9876
Copy link
Author

@christian-bromann thanks for the reply.

The problem is when the element being queried is a child of a child. Such as seen here: http://jsbin.com/topaku/edit?html,output

Or directly here:

  <div id="topdiv">
    <div>
      <label>Took</label>
    </div>
  </div>

First level descendants work fine, it is when the element is a deeper descendant that the problem manifests.

scags9876 added a commit to scags9876/webdriverio that referenced this issue Aug 8, 2016
Use xpath select `.//` instead of `./` to match elements anywhere in the descendant tree, instead of just in the first level of children.

Issue webdriverio#1465
@christian-bromann
Copy link
Member

Merged PR. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation Issues that require more information on the problem.
Projects
None yet
Development

No branches or pull requests

2 participants