han*_*oos 2 html javascript css jquery puppeteer
我正在尝试使用 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"]
Run Code Online (Sandbox Code Playgroud)
X路径:
//*[@id="survey-engine"]/span/div/div/div/div/div[2]/div/div[1]/input
Run Code Online (Sandbox Code Playgroud)
我一直无法让 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.
Run Code Online (Sandbox Code Playgroud)
(await page.$x("//input[contains(text(), 'My Input's Text')]"))[0];
Run Code Online (Sandbox Code Playgroud)
有没有人有任何想法?
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();
})
Run Code Online (Sandbox Code Playgroud)