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
Page.click() does not work with an input selector #3347
Comments
I'm running into the same issue. Strangely, if I use page.evaluate, it does work. For example:
I'd be curious if the same workaround works for you. |
Thanks. I think it was something to do with the form not uploading before the click event firing. Which is weird because in my launch function I explicitly asks it to wait until the page has been loaded. Nevertheless, I was able to fix it by adding some random delay: await page.goto('https://www.instagram.com/accounts/login/?source=auth_switcher'); Where addDelay is a user defined function to add random delay after 8 seconds. It still feels a bit "hacky" but it does work. You approach works too but I am still confused as to why the click function is not able to take in the input selector :( |
Maybe you should first waitforselector(), then click. |
Same issue. Using page.evaluate works but page.click does not. I am using waitForSelector(selector) immediately before page.click(selector) and it is not causing a timeout error. |
Here the same:
|
I'm having the same issue. |
I'm running into this issue (with
Using Puppeteer version: 1.14.0 |
Page.$eval isn't even working for me. |
Update:
|
Seems to be an issue on my Debian 9 docker container ( |
@mehtaanirudh: you put "waitUntil" in a wrong place: instead of putting it in Instead of relying on page loading status, it's better to use The following works just fine for me with pptr v1.14.0: const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless:false,
defaultViewport:{width:600,height:800},
});
const page = await browser.newPage();
await page.goto('https://www.instagram.com/accounts/login/?source=auth_switcher');
await page.waitFor('input[name="username"]');
await page.type('input[name="username"]', 'NewUser');
await browser.close();
console.log("Iam done!");
})(); Everybody else on this issue: if some clicking and typing doesn't work for you, please file a separate bug with us! Make sure to include a good reproduction script so that we can debug and see what's going on. |
Magically, |
@milottit same here, it‘s really mysterious. i‘ve got some e2e tests which work most of the time but sometimes, without any change in the ui, page.click is not working. i‘ll give the eval way a try. thx! |
still not working, i dont know why, i try |
@Peta5000 We fixed everything we knew that was not working with clicks. But since things sometimes don't work for you, there might be more! We can't just "fix" things - we need a good repro to run locally and debug things. Once you have one, please file a new issue! We'd be happy to look into it! |
@aslushnikov Problem is that it's really hard to create a demo where it fails all the time or even a demo where it fails sometimes. It happened really very sporadically in some of our applications and since I'm using the page.$eval() way @milottit suggested it didn't appear anymore. Perhaps it would make sense to examine the pptr page.click() function again keeping in mind that the page.$eval() way works and find out what the difference could be. |
@aslushnikov i try your solution, not working,
and it work. so, what do you think? |
Sometimes JS listener initialization is deferred - might be the case. |
do you have some puppeteer's way to check it? |
I'm able to see that in puppeteer 2.0.0, |
I've had this situation and it became very clear to me after I did a screenshot. In my case, button I was trying to click using + await page.evaluate(() => document.querySelector('#btn').scrollIntoView());
await page.click('#btn'); and it started working! It was mentioned before here: #2190 (comment). |
Ubuntu 18.04 I went through this whole page and tried every solution to click a button of type submit and none of these worked for me. . . . |
Try using
|
I tried to copy the js path from the log in button I wanted to be clicked on and it worked. The full function :
login: async (username, password) => {
|
The same problem here:
The WaitForSelector could find the selector, but the Click event dont. The soulution of Matt Russel works for me: "await page.evaluate((selector) => document.querySelector(selector).click(), selector); " |
I do not understand why google is not reacting to this issue originating back in 2018. |
I had the same issue and I went straight for page.evaluate (the website doesn't seem to distinguish between trusted and untrusted events, so no much bother on my side), but out of curiosity I dug a bit in the source code in GitHub. I got a bit lost in the process, so I'm not sure I'm pointing at the right direction, but maybe it's something in the click method of the Mouse class (at src/common/Input.ts), here the extract: async click(
x: number,
y: number,
options: MouseOptions & { delay?: number } = {}
): Promise<void> {
const { delay = null } = options;
if (delay !== null) {
await Promise.all([this.move(x, y), this.down(options)]);
await new Promise((f) => setTimeout(f, delay));
await this.up(options);
} else {
await Promise.all([
this.move(x, y),
this.down(options),
this.up(options),
]);
}
} To my understanding, Promise.all returns the promises in order, but it solves them out of order, therefore the two Promise.all should instead look like: async click(
x: number,
y: number,
options: MouseOptions & { delay?: number } = {}
): Promise<void> {
const { delay = null } = options;
if (delay !== null) {
await this.move(x, y);
await this.down(options);
// btw, I've seen this line a few times, might as well call it
// const sleep = (ms: number) => new Promise((f) => setTimeout(f, ms));
// somewhere in the code
await new Promise((f) => setTimeout(f, delay));
await this.up(options);
} else {
await this.move(x, y);
await this.down(options);
await this.up(options);
}
} This might explain the randomness in the behaviour. (Or, I'm wrong, and in that case I apologies for the wrong report 🙈 ) |
Steps to reproduce
Tell us about your environment:
What steps will reproduce the problem?
I am trying to use page.click() to go to the username filed in Instagram. If I use the selector input[name='username'] in developer console it works. However, puppeteer keeps throwing an error that no node was found
Please include code that reproduces the issue.
What is the expected result?
I should be able to type my username
What happens instead?
Puppeteer can't find the user name field
The text was updated successfully, but these errors were encountered: