Here is my simple code:
var element = await page.EvaluateExpressionAsync($"document.querySelectorAll('[{attributeName}=\"{attributeValue}\"]')[0];");
it will work correctly on the page, but it returns null
. where is the problem? I know it will execute correctly but I can not detect it on code.
If you want to get an element from the browser you should get an ElementHandle
, which is a pointer to an element in the browser, using EvaluateExpressionHandleAsync
:
var element = await page.EvaluateExpressionHandleAsync($"document.querySelectorAll('[{attributeName}=\"{attributeValue}\"]')[0];");