Reputation: 35
How can I select this (html anchor element to click and navigate to Tutorial page) query using puppeteer ?
I was doing this and it is not working
const puppeteer = require('puppeteer');
const url = process.argv[2];
if (!url) {
throw "Please provide URL as a first argument";
}
async function run() {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
slowMo: 10,
args: ['--start-maximzed', '--disable-notifications']
});
const page = await browser.newPage();
await page.goto(url);
await page.waitForSelector(".python-navigation .navigation.menu .tier-1.element-3 a", {
visible: true
});
await page.click(".python-navigation .navigation.menu .tier-1.element-3 a");
await page.waitForSelector(".documentation-banner .download-buttons ", {
visible: true
});
const elem = await page.$$('.documentation-banner .download-buttons a');
await elem[0].click();
await page.waitForSelector(".contentstable", {
visible: true
});
elem = await page.$$('.contentstable')[0].$$('tbody')[0].$$('tr')[0].$$('td')[0].$$('p')[1];
await elem.click();
await page.pdf({path: 'pdfGenerated.pdf',format:"A4"});
console.log("Success");
browser.close();
}
run();
What should I write instead of this line elem = await page.$$('.contentstable')[0].$$('tbody')[0].$$('tr')[0].$$('td')[0].$$('p')[1];
?
Upvotes: 2
Views: 1260
Reputation: 795
for click on an element you can use this code:
await page.click(".contentstable tbody tr td p:nth-child(2) a");
Upvotes: 1