playwright-go icon indicating copy to clipboard operation
playwright-go copied to clipboard

Find XPath from ElementHandle/JSHandle

Open unknownsoldier08 opened this issue 2 years ago • 0 comments

Hey guys, just wondering if it's possible to get a selected elements XPath with the playwright-go implementation?

I've tried to see if I can build the XPath myself, by reading up the parentElement in a node using the EvaluateHandle function on an ElementHandle. However, it seems to panic with the following error;

panic: interface conversion: interface {} is *playwright.elementHandleImpl, not *playwright.jsHandleImpl

func findXPath(handle playwright.ElementHandle) string {
  eval, _ := handle.EvaluateHandle(`(element) => element.parentElement`, handle)
  return eval.String()
}

Thanks for your help

unknownsoldier08 avatar Feb 26 '23 07:02 unknownsoldier08