Loop through JSHandle@array PuppeteerSharp

Viewed 322

I get the list of objects like this:

var elements = await page.EvaluateExpressionHandleAsync($"document.forms[0].getElementsByTagName('input')");

It returns a JSHandle@array, how can I iterate through its items?

1 Answers

That's an array in the browser. If you want to get that array on your site, you can use the GetPropertiesAsync method. It should be something like this:

var properties = await elements.GetPropertiesAsync().ConfigureAwait(false);
var elementsArray = properties.Values.OfType<ElementHandle>().ToArray();
Related