我正在尝试使用Puppeteer访问可点击的输入广播以推进我的应用程序调查。下面是选择器和xpath标记。
选择器:
#survey-engine > span > div > div > div > div > div.col-xs-12.col-xl-offset-2.col-xl-8.col-lg-offset-1.col-lg-10 > div > div:nth-child(1) > input[type="radio"]
XPath:
//*[@id="survey-engine"]/span/div/div/div/div/div[2]/div/div[1]/input
我无法使xpath或选择器正常工作。我也试过使用下面但没有运气。使用选择器查看错误:
>UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: No node found for selector: #survey-engine > span > div > div > div > div > div.col-xs-12.col-xl-offset-2.col-xl-8.col-lg-offset-1.col-lg-10 > div > div:nth-child(1) > input[type="radio"]
at Console.assert (console.js:194:23)
at Frame.click (/Users/erickloos/Desktop/phs-platform/node_modules/puppeteer/lib/FrameManager.js:597:13)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:48518) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:48518) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(await page.$x("//input[contains(text(), 'My Input's Text')]"))[0];
有没有人有任何想法?
答案 0 :(得分:2)
await page.evaluate(() => {
var test = document.querySelector('#survey-engine > span > div > div > div > div > div.col-xs-12.col-xl-offset-2.col-xl-8.col-lg-offset-1.col-lg-10 > div > div:nth-child(1) > input[type="radio"]')
test.click();
})
答案 1 :(得分:0)
你能不能简单地尝试(假设jquery在页面上)?
var input = await page.evaluate(() => {
return $('#survey-engine > span > div > ... > div:nth-child(1) > input[type="radio"]';
});
注意 为了简洁起见,我从您的问题中删除了一些选择器...