How to test result from page.evaluateHandle & el.nextElementSibling?

Viewed 103

How do you test that child actually contains the next Element Sibling or if there was NO next sibling found?

child = await page.evaluateHandle(el => el.nextElementSibling, child);

Nothing I've found seems to work. :(

1 Answers

Finally figured it out.

.nextElementSibling - returns a Node object or null.

.evaluateHandle - returns a jsHandle containing that result.

So you have to process the jsHandle container which holds the result.

jsHandle.asElement() - Returns either null or the object handle itself, if the object handle is an instance of ElementHandle.

You test for a failed result with:

if (child.asElement() === null) {
//do something
}
Related