Reputation: 79
I'm trying to access a clickable input radio using Puppeteer to advance in my application's survey. Below are the selector and xpath tags.
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"]
XPath:
//*[@id="survey-engine"]/span/div/div/div/div/div[2]/div/div[1]/input
I've been unable to get to the xpath or selector to work correctly. I've also tried using below but no luck. See error using selector:
>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];
Does anyone have any ideas?
Upvotes: 2
Views: 9967
Reputation: 79
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();
})
Upvotes: 5
Reputation: 22424
Can you not simply try (assuming jquery is on page)?
var input = await page.evaluate(() => {
return $('#survey-engine > span > div > ... > div:nth-child(1) > input[type="radio"]';
});
Note I removed some of the selectors from your question for brevity...
Upvotes: 0