jvppeteer icon indicating copy to clipboard operation
jvppeteer copied to clipboard

Best way to get innerText of an element

Open mahdix opened this issue 3 years ago • 2 comments

What is the best way to get text inside an HTML element like a span.

I am using below. Is that the best option?

Object value = elementHandle.evaluate("x => x.innerText", Collections.emptyList());

mahdix avatar Feb 19 '21 15:02 mahdix

This is the way to value in Java:

public static String getElementAttr(ElementHandle element, String param) { try { JSHandle jsHandle = element.getProperty(param); if (null == jsHandle) return ""; return jsHandle.jsonValue().toString(); } catch (Exception e) { return ""; } }

MaxBill avatar Feb 22 '21 01:02 MaxBill

Thanks @MaxBill. Do you know the difference between your approach and mine in terms of performance? Which one is faster?

mahdix avatar Feb 22 '21 09:02 mahdix