admin管理员组文章数量:1287928
I'm trying to automate retrieving form values from an already filled out form with puppeteer and xpath.
I've already automated FILLING a text input field as follows, but doing the reverse with .evaluate() doesn't work:
[fieldHandle] = await page.$x("//label[text() = 'My Label']/../following-sibling::td[1]//input")
await page.evaluate((x, y) => x.value = y, fieldHandle, 'newValue')
This is my most recent attempt - still no success...
let [fieldHandle] = await page.$x("//label[text() = 'My Label']/../following-sibling::td[1]//input")
let fieldRaw = await fieldHandle.getProperty('textContent')
let fieldValue = await fieldRaw.jsonValue()
Hopefully someone out there knows how to achieve this!
I'm trying to automate retrieving form values from an already filled out form with puppeteer and xpath.
I've already automated FILLING a text input field as follows, but doing the reverse with .evaluate() doesn't work:
[fieldHandle] = await page.$x("//label[text() = 'My Label']/../following-sibling::td[1]//input")
await page.evaluate((x, y) => x.value = y, fieldHandle, 'newValue')
This is my most recent attempt - still no success...
let [fieldHandle] = await page.$x("//label[text() = 'My Label']/../following-sibling::td[1]//input")
let fieldRaw = await fieldHandle.getProperty('textContent')
let fieldValue = await fieldRaw.jsonValue()
Hopefully someone out there knows how to achieve this!
Share Improve this question edited Feb 26, 2020 at 16:07 hardkoded 21.6k3 gold badges60 silver badges74 bronze badges asked Sep 4, 2019 at 21:53 remed.ioremed.io 3041 gold badge2 silver badges9 bronze badges3 Answers
Reset to default 16Using evaluate should work:
console.log(await page.evaluate(x => x.value, fieldHandle)));
This worked in my case
const name = await page.$eval("#usernameInput", (input) => {
return input.getAttribute("value")
});
you can use this simply..
const name = await page.$eval('//label[text() = 'My Label']/../following-sibling::td[1]//input"]', element => element.value);
本文标签: javascriptHow to access current value in a text input field with puppeteerStack Overflow
版权声明:本文标题:javascript - How to access current value in a text input field with puppeteer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738429570a2086319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论