Hello!
My objective is to detect if a WebElement is present.
So I wrote this code
List<WebElement> rows = CustomKeywords.'Table.getRowsOfATableById'(driver, 'A150')
for(int i = 1; i < rows .size(); i++) {
def exists = WebUI.verifyElementPresent(rows.get(i).findElement(By.xpath('//td/a')), 10)
if(exists) {
// exists
}
else {
// not exists
}
}
However this error occured
No signature of method: static verifyElementPresent() is applicable for argument types: (org.openqa.selenium.remote.RemoteWebElement, java.lang.Integer) values: [[[[[[[CChromeDriver: chrome on XP (a0b2b2416e09d1104b3459f96697ca64)] â id: A150]] â tag name: tr]] â xpath: //td/a], âŚ]
I donât know how to convert CChromeDriver in RemoteWebElement. Can you help me to fix it please?
It happened because I use packages org.openqa.selenium?
Thankâs a lot!
the parameter of verifyElementPresent should be testObject from Object repository - define one using your x-path and then use findTestObject() function
in your case you will defined parametrized xpath like: //tr[${RowNumber}]//td/a
and in findTestObject - findTestObject(âObject Repository/path_to_objectâ, [(âRowNumberâ) : cycle_var])
I already tried to create a TestObject and add a property.
TestObject to = new TestObject();
to.addProperty("xpath", , ConditionType.EQUALS, ?????)
But I donât know how to build the XPath Expression based on rows which are recovered with the loop.
Hi Nicolas,
you are trying to pass RemoteWebElement as a parameter to verifyElementPresent, which expects TestObject instead. You need to convert RemoteWebElement to TestObject. Or - and it looks like better solution - use isDisplayed() method from WebElement class.
for(WebElement elem : webElemList) {
boolean exists = elem.isDisplayed()
if(exists) { // exists
}
else {
// not exists
}
}
1 Like
my guess is that you are trying to get table based on ID (A150), then all itâs rows and then check if row have TD with tag
my xpath will be looking like : //table[@id=${TableID}]//tr[${RowNumber}]//td/a
i would go with something like this (more Katalon solution):
int rowCount = driver.findElements(By.xpath(â//table[@id=âA150â]//trâ)).size()
for (def i : (1âŚrowCount)) {
WebUI.verifyElementPresent(findTestObject(âObject Repository/path_to_objâ, [(âTableIDâ) : âA150â,(âRowNumberâ) : i]))
}
P.S.: iâm writing this from memory so errors can be found in above
Hi @Marek Žitný , first thanks for your answer.
Every elements of webElemList exists.
Here an html example.
<table id="A150">
<tr>
<td> some text </td>
</tr>
<tr>
<td> <a id='5' href='...'>Link</a>
</tr>
<tr>
<td> some text </td>
</tr>
</table>
With this example, webElemList contains three elements (
tags). But I want to know if for each row (
tag) a tag with id â5â exists or not.
@Andrej PodhajskĂ˝ thankâs!
I will try this solution.