question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page.click() does not work with an input selector

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.8.0
  • Platform / OS version: Windows 10
  • URLs (if applicable):
  • Node.js version: 8.11.4

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.

const puppeteer = require('puppeteer');

(async () => {
	 try {
	const Browser = await puppeteer.launch({headless:false,
										defaultViewport:{width:600,height:800},
										waitUntil: ['load','domcontentloaded','networkidle0','networkidle2'],
						                timeout :0
						            	});
	const page=await Browser.newPage();
		
    await page.goto('https://www.instagram.com/accounts/login/?source=auth_switcher');
    
    await page.click('input[name="username"]');

    await page.keyboard.type('NewUser');
	await Browser.close();
	
	console.log("Iam done!");
	

	} catch(e) {console.log('main program error:' + e);
	}
	
})();

What is the expected result?

I should be able to type my username

What happens instead?

Puppeteer can’t find the user name field

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:27 (5 by maintainers)

github_iconTop GitHub Comments

76reactions
russelldmattcommented, Oct 5, 2018

I’m running into the same issue. Strangely, if I use page.evaluate, it does work. For example:

let selector = 'input[name="username"]';

// does not work
await page.click(selector); 

// does work
await page.evaluate((selector) => document.querySelector(selector).click(), selector); 

I’d be curious if the same workaround works for you.

35reactions
quarhodroncommented, Mar 27, 2019

Here the same: await page.$eval('#link', elem => elem.click()); // works

await page.click('#link'); // doesn't work

const btn= await page.waitForSelector('#link'); await btn.click(); // doesn't work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer page.click CSS selector not working
I tried doing something like the examples below: await page. click("ul. select2-selection__rendered:nth-of-type(2)>li>input");
Read more >
<input type="button"> - HTML: HyperText Markup Language
The script gets a reference to the HTMLInputElement object representing the <input> in the DOM, saving this reference in the variable button ....
Read more >
Page.click() method
This method fetches an element with selector, scrolls it into view if needed, and then uses Page.mouse to click in the center of...
Read more >
Element selectors | Playwright
Selectors are strings that point to the elements in the page. They are used to perform actions on those elements by means of...
Read more >
Handling Events
Clicks on the button cause that handler to run, but clicks on the rest of the document do not. Giving a node an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found