我一直收到错误 TypeError:无法读取null的属性“ setAttribute”
这是元素:
<input type="text" name="fields[name]" class="form-control" placeholder="Full
Name*" autocomplete="name" x-autocompletetype="name"
spellcheck="false" autocapitalize="off" autocorrect="off">
这是我的代码(使用操纵up):
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.setUserAgent(userAgents[Math.floor(Math.random()*userAgents.length)]);
await page.goto('website here');
await page.evaluate(() => {
document.querySelector('[placeholder="Full Name*"]').setAttribute('value', 'test');
});
我也使用过:
document.querySelector('[name="fields[name]"]').setAttribute('value', 'Test');
我还尝试了使用xpath,但都失败了。
重要的是要注意,querySelector行在chrome控制台中运行良好,所以我不知道为什么它在这里不起作用... 希望获得任何帮助。