puppeteer-sharp

how to get the activeElement in puppeteer sharp


In order to find the activeElement in javascript puppeteer you use:

await page.evaluateHandle(() => document.activeElement);

But i cant find this in Puppeteer Sharp.

is there a way to do this?

I'm trying to find the activeElement, check if it has a certain innerText, and if so, click it.


Solution

  • You are after a handle, in this case an IElementHandle then you use EvaluateExpressionHandleAsync

    var activeElement = await (IElementHandle)Page.EvaluateExpressionHandleAsync("document.activeElement");
    

    There are more examples on GitHub