Hi
I am working on a Katalon studio test case and I need to find a table element but I cant. Whenever I try to do it, it fails:
This is the error: “no such element: Unable to locate element”
To fix this I tried various things:
- try to find table by id
- try to find element by xpath
- try to find element by full xpath
- try and follow this:
Trying to find object by Xpath "How to handle Web Tables"
None of this worked for me.
One of the things I usually do is to try and use the spy web tool. This usually helps me a lot but whenever I try to locate the element with this, the tool can not find it. (no red border shows up in element)
This is the code I am using:
WebUI.callTestCase(findTestCase(‘Veterinaria/7-Ingreso y validacion de resultados 2’), [:], FailureHandling.STOP_ON_FAILURE)
WebDriver driver = DriverFactory.getWebDriver()
WebElement Table = driver.findElement(By.xpath('/html/body/form/div[2]/div[2]/div/div/div/div/div[2]/div/table/tbody/tr[2]/td/div/div/div/div/div/div/div/div/table/tbody/tr[2]/td/div/div/table/tbody/tr/td/table'))
//WebElement Table = driver.findElement(By.xpath("//table[@id=\'Grid1ContainerTbl\']/tbody"))
List<WebElement> Rows = Table.findElements(By.tagName('tr'))
//List<WebElement> tr_withInput = Table.findElements(By.xpath('//tr[*//input[contains(@id, \'vRESULTADOVALOR_\')]]'))
table: for (int i = 1; i < Rows.size(); i++) {
println('Aqui estoy ' + Rows(i))
TestObject toV = new TestObject()
String objectXpathV = CustomKeywords.'keywordPrueba.CustomFunction.getDynamicObjects'('//input[@id=\'vRESULTADOVALOR_', i)
toV.addProperty('xpath', ConditionType.EQUALS, objectXpathV)
if (WebUI.verifyElementNotPresent(toV, 5, FailureHandling.OPTIONAL)) {
break
} else {
WebElement elementPrueba = WebUiCommonHelper.findWebElement(toV, 5)
String textInsideInputBox = elementPrueba.getAttribute('value')
if (textInsideInputBox.isEmpty()) {
CustomKeywords.'keywordPrueba.CustomFunction.clickUsingJS'(toV, 5)
WebUI.executeJavaScript('arguments[0].value=\'12\'', Arrays.asList(elementPrueba))
}
}
}
This is the html code:
If you have any suggestions on how to resolve this, I would be very happy
Thanks