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
Puppeteer Won't Click on Element #1805
Comments
Try to set a time before clicking... await this.page.waitFor(2000);
await this.page.click('#idSIButton9'); |
That worked. Thanks. I thought that waitFor(selector) would have achieved the same thing, but I guess not. Thanks for the answer. |
@paul-phillips-ark it looks like the javascript code responsible for handling button clicks is not evaluated yet; the |
I managed to get around this by first selecting the submit button, and then typing a "\n" await page.focus(' tr:nth-child(3) > td:nth-child(2) > input[type="submit"]' ) |
@immauss' solution worked out for me. thanks! |
Thanks! This solution worked for me when no others worked. |
Thanks @immauss, your solution worked for me as well after a day of investigation! |
Worked for me as well, although I'm wondering why is it so weird and the plain .click method is not working 🤔 |
Wondering why the plain |
click still doesn't work but in my case any other ways didn't worked too |
In my case, I'm able to use this reliably:
|
I'm having the same issue trying to click a button that is conditionally rendered (with React btw). |
@michellocana try @immauss solution. That works well (in a React app) |
I have to admit that I don't see why something like await page.$eval('h3', titles => titles[1].click()) is not working... Even that one is not good neither let selectors = await page.$$('h3')
await page.$$eval(selectors[1].click()) neither this one... const result = await page.evaluate(async() => {
let selectors = document.querySelectorAll('h3')
await page.click(selectors[1])
}) |
@kissu same, 3 solutions all not working. |
same, what I can do? |
@salemalem not sure what actually the |
@kissu The problem noted was that simply using |
For me what ended up working was simulating a 'tab' press until I got to the button, then hitting 'enter':
|
Try using
|
We are still experiencing this issue in 4.4.0. Switching to |
Not to be a broken record, but does anyone understand why eval would work but click would not? In my case, I have two tests inside of a describe block in jest, and click works in the first but not in the second...
version is 2.1.1 |
Given that some people are having success with await, I'm assuming it's got something to do with click being triggered before the element exists on the page? |
In my case, I think the click is being triggered before the button is enabled. frustrating to have to explicitly wait 300ms: |
same with @banderson858 - adding page.waitFor(some time) works, perhaps the dom is loaded into the array |
this man saved my life thank you. |
I tried all solutions provided above but none worked. Then I realized that the button was outside of the visible region in my browser (not using headless puppeteer since I am testing my script and want to see if it works). I just put the focus on the element and clicked. It worked. await page.waitForSelector(mySelector); |
my situation: // not work
await page.waitForSelector(mySelector);
await page.click(mySelector);
// not work
await page.waitForSelector(mySelector);
await page.focus(mySelector);
await page.click(mySelector);
// work
await page.$eval(mySelector, (elem) => elem.click()); |
same situation here @zoffyzhang |
That worked man!! Thanks |
Thanks! That worked for me |
It worked for Me thanks u so much ! |
Just wanted to drop a note to explain why doing
Depending on your use case, one might be more appropriate than the other! Hope this helps someone if they're smashing their head into their desk trying to understand how these are different (as I did) |
I got it worked out using I.forceClick(selector); |
Nothing is working for me. I tried everything. |
My journey of pain: Element that needs to be clicked in order to make visible a popup that I then need to scrape:
1st try:
Got error: 2nd try: Becaus it is actually a list of items I have to click:
Got error: 3rd try: To make debugging easier, I contented myself with trying to just click the 1st item in the list:
Works 50% of the time, plus I have a timeout of 2 sec. Obviously not ideal. 4th try: According to above comments:
Never works. Is this lib even production ready? I'm wasting a lot of my clients money here. |
Why this is closed? Simple script which reproduces the issue: import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set');
await Promise.all([
page.waitForNavigation(),
page.click('#set\\.prototype\\.keys > a')
]);
await browser.close();
})(); Obviously the logic of |
This patch fixes page.#scrollIntoViewIfNeededso that it works with devtools protocol. Now it blocks the main thread and waits until the scrolling action finishes. Issues: puppeteer#8627, puppeteer#1805 BREAKING CHANGE: page.#scrollIntoViewIfNeeded throws erros which come from the internal implementation. - `Protocol error (DOM.scrollIntoViewIfNeeded): Node is detached from document` - `Protocol error (DOM.scrollIntoViewIfNeeded): Node does not have a layout object` Also now it does work with TextNode properly and does not throw an error.
This patch fixes page.#scrollIntoViewIfNeeded, so that it works with devtools protocol. Now it blocks the main thread and waits until the scrolling action finishes in Chrome. Fallbacks to the old implementation if `DOM.scrollIntoViewIfNeeded` is not supported for Firefox. Issues: puppeteer#8627, puppeteer#1805
This patch fixes page.#scrollIntoViewIfNeeded, so that it works with devtools protocol. Now it blocks the main thread and waits until the scrolling action finishes in Chrome. Fallbacks to the old implementation if `DOM.scrollIntoViewIfNeeded` is not supported for Firefox. Issues: puppeteer#8627, puppeteer#1805
This patch fixes page.#scrollIntoViewIfNeeded, so that it works with devtools protocol. Now it blocks the main thread and waits until the scrolling action finishes in Chrome. Fallbacks to the old implementation if `DOM.scrollIntoViewIfNeeded` is not supported for Firefox. Issues: puppeteer#8627, puppeteer#1805
This patch fixes page.#scrollIntoViewIfNeeded, so that it works with devtools protocol. Now it blocks the main thread and waits until the scrolling action finishes in Chrome. Fallbacks to the old implementation if `DOM.scrollIntoViewIfNeeded` is not supported for Firefox. Issues: puppeteer#8627, puppeteer#1805
How can this issue be closed? This is plenty of ridiculous bugs |
@ManelGonzalez-ops pls report a new issue with the repro if you believe you encountered the bug. |
Also came across this, had to use:
instead of:
|
This works fine for me, but how can you do it with page.$$eval() with multiple button elemets? Please note, that when each clicks occurs. then a series of actions should take place some of them using page (which is not accessible inside eval). |
For people who are trying to click on await page.evaluate(() => document.querySelector("selector").setAttribute("tabIndex", "1"));
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
// After pressing tab and enter, you've essentially opened the selecting element. |
`const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)); await delay(2000); working for me 2024` |
Trying to get Puppeteer to navigate through my login page which will bring the automated test to the main page of my site. It all works until it reaches 'waitFor('#idSIButton9');'. Puppeteer successfully enters the password and username but can't seem to select the submit button(#idSIButton9). Any idea what might be going wrong here? Let me know if you guys need more info. Thanks :)
The text was updated successfully, but these errors were encountered: