I have WebElement which I have to convert into Testobject in katalon using groovy script.
For Example
List<WebElement> WEs = WebUI.executeJavaScript("return document.querySelector('#email').parentElement", [])
Now I want to convert WEs[0] to TestObject which Katalon accepts.
Please let me know if you have an idea about this.
There is no direct way to convert WebElements to TestObjects. According to this forum question, you could create a function to get the xpath of the web element
protected String getXPathFromElement(RemoteWebElement element) {
String elementDescription = element.toString();
return elementDescription.substring(elementDescription.lastIndexOf("-> xpath: ") + 10, elementDescription.lastIndexOf("]"));
}
and then create a new test object with the given xpath:
protected TestObject fromElement(RemoteWebElement element) {
TestObject testObject = new TestObject();
testObject.addProperty("xpath", ConditionType.EQUALS, getXPathFromElement(element));
return testObject;
}
NOTE:
For other way around (Test Object -> WebElement), use
WebUiCommonHelper.findWebElement(test-object, timeout)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With