-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Adds a waitForXpath method to page and frame. #1767
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
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
@aslushnikov please review! |
|
CLAs look good, thanks! |
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The // heuristic makes me a bit uncomfortable. It further fractures this method and doesn't include all xpath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a pragmatic heuristic, and there's waitForXpath if you have something else. importantly anything starting with // is NOT valid css.
I don't feel strongly about it though, and I'm happy to just remove support for Xpath from waitFor if this is a blocker.
I thought of using xpath if it's valid xpath, or css if it's valid css, but there's some overlap there, and I'm not sure if the meaning would always be the same.
I'm open to any other alternatives you can think of as well, but I didn't come to this thoughtlessly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry reading back my response, it sounds a bit douchy the next day. I appreciate your dedication to keeping the API clear and I'm happy to fix this PR until it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically the only thing that will work without an inital // is something that starts with
"html/body/" and I don't think this is how people use xpath, but I might be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a fresh look, I like this. Thanks!
lib/FrameManager.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with XPath, but maybe we want Xpath.FIRST_ORDERED_NODE_TYPE to get some consistency with the results.
lib/FrameManager.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a lot of code shared with waitForSelector. I think we should pop it out into its own function, and add an xpath/selector argument to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed some duplication.
lib/FrameManager.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
test/test.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we share the same predicate code with waitForSelector, I think a lot of these tests become redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the code to be shared. Which ones do you think we should keep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I've used my best judgement and removed most of them.
|
Thanks for the PR! Looks good! |
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bottom reference for [xpath] link is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, missed that. added the link.
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in the hash:
#pagewaitforsxpathxpath-options -> #pagewaitforxpathxpath-options
------------^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are eagle-eyed sir. fixed.
|
CLAs look good, thanks! |
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate sentences)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same typo)
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comma intended (here and in the page counterpart)?
95b6ae3 to
af5f403
Compare
|
hey just following up on this branch, don't want it to get forgotten. I believe I've responded to all the excellent feedback, PTAL |
|
@fringd Sorry, I am not a maintainer, just a contributor like you) |
|
@JoelEinbinder gentle ping, if there's more you want to get this merged, please let me know. |
docs/api.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think xpath is capitalized as XPath for the link, and that would make it waitForXPath as the method name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
lib/FrameManager.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these days ElementHandle is actually fine to use for nodes. We use it internally as a reference to the Document node. So this check can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, fixed this code to work with text nodeds and adding a test to verify selecting textNode works
lib/FrameManager.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing as we are using an imperfect heuristic, I think we can be more aggressive and say its an XPath if it just starts with /. string.startsWith('/') .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, SGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay! Looks good, with some small comments.
|
thanks for the review, and no problem about the wait. congrats on 1.0 BTW ^_^ |
|
@JoelEinbinder PTAL thx ^_^ |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
CLAs look good, thanks! |
| version "2.0.2" | ||
| resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" | ||
|
|
||
| exit@^0.1.2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think yarn.lock should change with this patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted this change.
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
CLAs look good, thanks! |
|
ping @JoelEinbinder I removed the yarn.lock changes. not sure how I altered those, It must have been some bad git rebasing. |
lib/FrameManager.js
Outdated
| waitFor(selectorOrFunctionOrTimeout, options = {}, ...args) { | ||
| if (helper.isString(selectorOrFunctionOrTimeout)) | ||
| return this.waitForSelector(/** @type {string} */(selectorOrFunctionOrTimeout), options); | ||
| const xpathPattern = /^\//; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's check for double-slash here, otherwise it gonna be a breaking change.
Consider the following usecase:
const crazySelector = '/* comment */div';
await page.waitFor(crazySelector);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crazy, fixed.
lib/FrameManager.js
Outdated
|
|
||
| if (helper.isString(selectorOrFunctionOrTimeout)) { | ||
| const string = /** @type {string} */ (selectorOrFunctionOrTimeout); | ||
| if (string.match(xpathPattern)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's do string.startsWith instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/FrameManager.js
Outdated
| const string = /** @type {string} */ (selectorOrFunctionOrTimeout); | ||
| if (string.match(xpathPattern)) | ||
| return this.waitForXPath(string, options); | ||
| else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: drop else. (We follow blink's codestyle)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
@JoelEinbinder @aslushnikov made some more changes in response to feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fringd thank you very much for prompt responses!
Here's a waitForXpath function as per issue 1757