So I'm trying to get an input element from Twitter but when I run it it keeps giving me an error like this in node terminal and as a result the browser window created by this code will close itself as it finds Not having the correct input selector. How do I get the correct type of input?
Error: Element of selector not found: input[name="text"]
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ headless: false, }) const page = await browser.newPage(); page.setViewport({ width: 1280, height: 800, isMobile: false }) await page.goto("https://twitter.com/i/flow/login"); await page.type('input[name="text"]', 'username', {delay: 25}) })();
I tried different selectors, including the class
attribute, but I still get the error
P粉7041966972024-04-07 11:23:31
You need to waitForSelector appear on the page before entering. That's why you get the error, it can't find the element.
await page.waitForSelector('input[name="text"]'); await page.type('input[name="text"]', 'username', {delay: 25})