Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert WebElement to TestObject in katalon studio?

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.

like image 816
Rohit Ramani Avatar asked Oct 21 '25 05:10

Rohit Ramani


1 Answers

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)
like image 118
Mate Mrše Avatar answered Oct 23 '25 19:10

Mate Mrše



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!