Skip to content

Conversation

@fringd
Copy link
Contributor

@fringd fringd commented Jan 10, 2018

Here's a waitForXpath function as per issue 1757

@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address on your commit. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot. The email used to register you as an authorized contributor must be the email used for the Git commit.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@fringd
Copy link
Contributor Author

fringd commented Jan 10, 2018

I signed it!

@googlebot
Copy 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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@fringd
Copy link
Contributor Author

fringd commented Jan 10, 2018

@aslushnikov please review!

@googlebot
Copy link

CLAs look good, thanks!

docs/api.md Outdated
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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!

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed some duplication.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

@JoelEinbinder
Copy link
Contributor

Thanks for the PR! Looks good!

docs/api.md Outdated
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@googlebot
Copy 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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

docs/api.md Outdated
Copy link
Contributor

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
------------^

Copy link
Contributor Author

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.

@googlebot
Copy link

CLAs look good, thanks!

docs/api.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate sentences)

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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)?

@fringd fringd force-pushed the xpath branch 2 times, most recently from 95b6ae3 to af5f403 Compare January 11, 2018 01:12
@fringd
Copy link
Contributor Author

fringd commented Jan 12, 2018

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
Copy link
Contributor Author

fringd commented Jan 12, 2018

@vsemozhetbyt @JoelEinbinder ^^

@vsemozhetbyt
Copy link
Contributor

@fringd Sorry, I am not a maintainer, just a contributor like you)

@fringd
Copy link
Contributor Author

fringd commented Jan 16, 2018

@JoelEinbinder gentle ping, if there's more you want to get this merged, please let me know.

docs/api.md Outdated
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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('/') .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, SGTM

Copy link
Contributor

@JoelEinbinder JoelEinbinder left a 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.

@fringd
Copy link
Contributor Author

fringd commented Jan 17, 2018

thanks for the review, and no problem about the wait. congrats on 1.0 BTW ^_^

@fringd
Copy link
Contributor Author

fringd commented Jan 19, 2018

@JoelEinbinder PTAL thx ^_^

@googlebot
Copy 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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"

exit@^0.1.2:
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted this change.

@googlebot
Copy 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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

@fringd
Copy link
Contributor Author

fringd commented Jan 22, 2018

ping @JoelEinbinder I removed the yarn.lock changes. not sure how I altered those, It must have been some bad git rebasing.

waitFor(selectorOrFunctionOrTimeout, options = {}, ...args) {
if (helper.isString(selectorOrFunctionOrTimeout))
return this.waitForSelector(/** @type {string} */(selectorOrFunctionOrTimeout), options);
const xpathPattern = /^\//;
Copy link
Contributor

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

crazy, fixed.


if (helper.isString(selectorOrFunctionOrTimeout)) {
const string = /** @type {string} */ (selectorOrFunctionOrTimeout);
if (string.match(xpathPattern))
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

const string = /** @type {string} */ (selectorOrFunctionOrTimeout);
if (string.match(xpathPattern))
return this.waitForXPath(string, options);
else
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@fringd
Copy link
Contributor Author

fringd commented Jan 22, 2018

@JoelEinbinder @aslushnikov made some more changes in response to feedback.

Copy link
Contributor

@aslushnikov aslushnikov left a 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!

@aslushnikov aslushnikov merged commit cb684eb into puppeteer:master Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants