Basically, i'm trying to log in into this form:
using this script:
const puppeteer = require('puppeteer')
const screenshot = 'carwow.png'
const scrape = async () => {
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
await page.goto('https://dealers.carwow.co.uk/dealers/sign_in')
await page.type('input type="email"', 'username')
await page.type('input type="password"', 'password')
await page.click('name="commit"')
await page.waitForNavigation()
await page.screenshot({ path: screenshot })
browser.close()
console.log('See screenshot: ' screenshot)
};
scrape()
However, its failing with an error as such: Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': 'input[value type="email"' is not a valid selector.
CodePudding user response:
I'm not super familiar with puppeteer but it looks like the API you're trying to use, e.g. page.type is documented here: https://github.com/puppeteer/puppeteer/blob/v10.4.0/docs/api.md#pagetypeselector-text-options and it uses CSS selectors for the first argument to test against.
Specifically an attribute selector on an input, here is a short document from W3 on it: https://www.w3schools.com/css/css_attribute_selectors.asp
You may want to try the selector
'input[type="email"]'
CodePudding user response:
@Diego is right. You can rewrite your selector paths as below:
'input[type="email"]'
and 'input[type="password"]'
and "*[name='commit']"