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

fix(frame): Fix Frame.waitFor's XPath pattern detection #5184

Merged
merged 6 commits into from Sep 15, 2021

Conversation

xprudhomme
Copy link
Contributor

@xprudhomme xprudhomme commented Nov 21, 2019

Up to now, only strings starting with '//' are considered as to XPath selectors.

Unfortunately, this is too restricting and leads to errors especially when asking the page to wait for XPath selectors not starting with '//'.

If the XPath is something like '(//div)[4]/@itemprop' then it is passed to the waitForSelector method and eventually document.querySelector, which in turn throws an error because it does not recognize it as a valid CSS selector.

Because of this, I had to implement something like this in my code:

await isXPathSelector(selector)
            ? page.waitForXPath(selector)
            : page.waitForSelector(selector);

This fix allows the use of valid XPath selectors starting with parenthesis and to be recognized as such by the Frame's waitFor method.

    Up to now, only strings starting with '//' are considered as to XPath selectors. Unfortunately, this is too restricting. This fix allows valid XPath selectors starting with: '/', './', and even '(//*[1])'
@mathiasbynens
Copy link
Member

This needs tests.

@xprudhomme
Copy link
Contributor Author

It's my first PR here. Never done any test for this before.
Any help appreciated for implementing required tests.
Thanks :)

@mathiasbynens
Copy link
Member

Look for the existing waitForXPath tests and add some examples that failed without your patch, but now work.

This patch allows to wait for and select an element with a parenthesis-starting xpath. Before this, only double slashes starting xpath were allowed.
@xprudhomme
Copy link
Contributor Author

Ok thanks.

I've changed the xPathPattern to allow for the use of XPath starting with not only "//" but also with an opening parenthesis.

In my last commit, I've also added a new test accordingly.

Copy link
Contributor

@jschfflr jschfflr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xprudhomme Thanks for your contribution! Please resolve the merge conflicts and I'm happy to get this landed!

@google-cla
Copy link

google-cla bot commented Sep 14, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Sep 14, 2021
@jschfflr
Copy link
Contributor

@googlebot I consent.

@google-cla google-cla bot added cla: yes and removed cla: no labels Sep 14, 2021
@jschfflr jschfflr enabled auto-merge (squash) September 14, 2021 18:38
@jschfflr jschfflr merged commit caa2b73 into puppeteer:main Sep 15, 2021
This was referenced May 30, 2022
This was referenced May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants