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

Nothing happens on clicking a button when headless true #2959

Closed
ziadali1 opened this issue Jul 26, 2018 · 17 comments
Closed

Nothing happens on clicking a button when headless true #2959

ziadali1 opened this issue Jul 26, 2018 · 17 comments

Comments

@ziadali1
Copy link

  • Puppeteer version: 1.5.0
  • Platform / OS version: Win 7
  • Node.js version: 9.10.1

When i execute the code with headless: false everything works fine. However, when setting to true, nothing happens when clicking a button.

await page.waitForSelector('#search > input[type="text"]');    
await page.type('#search > input[type="text"]', '000000');
await page.click('#search > button');

await page.waitForSelector('#result > div > h2');
console.log('after waitfor h2'); //working with headless false only

Any reason not to work? Maybe some blocking from the website? (i do not have access to the source code).

@aslushnikov
Copy link
Contributor

Can you provide a repro that I can run locally? There's no way I can debug this otherwise.

@ziadali1
Copy link
Author

ziadali1 commented Jul 27, 2018

Unfortunately i can't. I can only reproduce the error accessing the web application and it's protected with password that i can't share.
One thing i noticed tho..

System.User.Services.funcao = 0;
if(System.User.Services.funcao == 0) {
    $("#main").remove();
}

Conditions like the above is working when non-headless, however it fails when headless. This #main is only showing up on headless mode (through screenshots). Apparently jquery is not working when headless.

@ziadali1
Copy link
Author

await page.on('console', msg => {
        console.log(msg);
 });  

await page.evaluate(() => {
        jQuery(function($) {
            console.log('jquery loaded!');
        });
});

I get the message only when running non-headless.

@ziadali1
Copy link
Author

I just caught the error: "ReferenceError: chrome is not defined".

@dge808
Copy link

dge808 commented Aug 6, 2018

@ziadali1 I'm not an expert, but maybe you should try to add
page.waitFor(5000);
before
await page.click('#search > button');

@ziadali1
Copy link
Author

ziadali1 commented Aug 6, 2018

@dge808 not the case :(
I noticed the website is using extensions at the chrome inspector (sources tab) even though i do not have any installed. Since headless chrome doesn't load extensions, this might be the cause. I was forced to switch to non-headless.

Thank you for your help.

@Kalevera
Copy link

Kalevera commented Aug 15, 2018

I'm having a related issue (in bith headless and non-headless modes).

Where I can use
page.focus('#elmID') and chromium shows the button becomes focused, but trying to click the element with page.click('#elmID') will throw an error in the ElementHandler stating the node is not visible or not an HTMLElement.

This worked prior to upgrading to node 8 and Puppeteer V 1.7.0

Any reason as to why ElementHandler can't find the JSHandlerobject? I tried looking at lib source to see if something was not referencing the correct array of objects but didn't find any issues.

Any one else getting this issue?

I've also tried the page.waitFor(3000); prior to the click event.

EDIT: I updated chromium and removed executable path from puppeteer.launch() and that resolved my problems.

Maybe upgrade chromium or reinstall new puppeteer bundle.

@jesperalmstrom
Copy link

@Kalevera I have the same issue.
Using Puppeteer Core v1.7.0 together with Chrome Version 68.0.3440.106 (Official Build) (64-bit)
This worked before updating Chrome on my CentOS 7 (Linux).
page.click('#continue') in my case does not work anymore.

@Kalevera
Copy link

@jesperalmstrom are you using the chromium version that's bundled with the GitHub npm package or are you using a different chromium version and using puppeteer.launch(executablepath: path/toNON/bundled/chromium.exe)?

I updated the chromium version I was using to the bundled version in recent update and that fixed the page click issue.

@jesperalmstrom
Copy link

@Kalevera I have had major issues getting the bundled chromium to install on my CentOS box. Now i use Puppeteer Core to skip chromium. I could work around the problem with
await page.keyboard.press('Enter');
Instead of clicking the button.

When I look at my git log I see that I have had problem before with page.click so for some reason it does not cope well with Chrome.

@aslushnikov
Copy link
Contributor

@jesperalmstrom please make sure to use proper puppeteer-core version for your chrome; the compatibility table could be found in our docs: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md

@Kalevera can you share your script? It's hard to say anything without an actual script I can play with.

@Kalevera
Copy link

@aslushnikov my issue was resolved once I updated my chromium to the latest bundled version.

@thamerla
Copy link

thamerla commented Feb 3, 2019

@aslushnikov happens after upgrade to 12.1. Windows, built-in version of chromium.

@bachega8
Copy link

I get this problem when i try to perform some click in the page. I solved this using a diferent way
to perform clicks. Check out:

Before:

let login_button = await page.$x('//a[contains(text(), "Login")]')  
 await login_button[0].click()

After:

await page.evaluate(() => {
        let but = document.querySelector("span[class='pr-2 pr-sm-2 pr-lg-4 pl-sm-2 pl-md-2 pt-1 pb-1 nao_logado active'] > a")
        if (but) {
            return Promise.resolve(but.click())
        }
    })

I don't know why, but using "evaluate()" i can click on page buttons and links with background, minimized mode

@tatianailchenko7
Copy link

this helped me: await page.evaluate(()=>document.querySelector('.css-19t649w').click())

@matheuscamarques
Copy link

this happens to me too

@Kalevera
Copy link

Kalevera commented Jun 9, 2022

Hey this still works so try upgrading or installing because the chromium version works using this. Also you can change the executable to a standard chrome version if you're unable to download the chromium bundled version.

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

No branches or pull requests

9 participants