miyakogi / pyppeteer

Headless chrome/chromium automation library (unofficial port of puppeteer)
Other
3.57k stars 371 forks source link

Getting selector out of xpath #239

Open ivaylogb opened 5 years ago

ivaylogb commented 5 years ago

I could be wrong here, but I've tried every possible variation so if this is doable in pyppeteer please let me know. I have an xpath string and I'd like to get the selector out to call page.click("selector string"). Right now the logical progression is to call page.xpath(xpath_string) which returns an elementHandler object that in theory represents the DOM-based object that the xpath refers to. However, there is no progression that fetches the selector string based on that elementHandler (In the javascript version, you can directly call page.click on the xpath return value but this is not the case with pyppeteer

goswami-rahul commented 4 years ago

You can click the element using ElementHandle.click().

elements = await page.xpath(xpath_string)
for element in elements:
    element.click()