Hi all , In my project, I want to loop all over the page icons.
I’ve try but it iterates only the one icon but not all.
Some helps please !!!
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import com.kms.katalon.core.webui.driver.DriverFactory
String xpath = "//path"
List elems = DriverFactory.getWebDriver().findElements(By.xpath(xpath))
for(WebElement elem in elems) {
elem.click()
}
In my case I want click on plus icon
but it is not working for me
Now I got those icons expaths-
//table[@class=‘table noAdjust table-bordered table-hover tree-check-table no-footer dataTable DTFC_Cloned’]//i[starts-with(@id, “gradeShift-”)]
Now I want to click on those icons one by one
how Can I perform these task…? plz help on this
It is clicking on first plus icon but not second…
It says StaleElementException - something changes on your page during test execution. Probably second element changes when you click on first one. Can you investigate more?
String xpath = “//table[@class=‘table noAdjust table-bordered table-hover tree-check-table no-footer dataTable DTFC_Cloned’]//i”
List elems = DriverFactory.getWebDriver().findElements(By.xpath(xpath))
for(WebElement elem in elems) {
WebUI.delay(1)
elem.click()
}
I used same code for clicking on those plus icon
//table[@class=‘table noAdjust table-bordered table-hover tree-check-table no-footer dataTable DTFC_Cloned’]//i”
For this xpaths I got tow elements
accourding to the image below
How can I proceed more plz help on this…?
Can you evaluate the XPath in browser after you click on first plus button?
It’s because your xpath capture all i[starts-with(@id, “gradeShift-”)]
elements (the minus icons too)
Use
//table[@class='table noAdjust table-bordered table-hover tree-check-table no-footer dataTable DTFC_Cloned']//i[contains(@class, 'fa-plus-circle')]
as @Marek_Melocik saids
xpath was //i[... xpath="2"]
and becomes //i[... xpath="1"]
You have to refresh your object detection
Thank you…
How can I refresh object detection…?
plz give me some description…
You can try something like
List elems = DriverFactory.getWebDriver().findElements(By.xpath(xpath))
for(WebElement elem in elems) {
WebUI.delay(1)
elem.click()
elems = DriverFactory.getWebDriver().findElements(By.xpath(xpath))
}
Or use an other method like
TestObject to = new TestObject('plus_button')
String xpath = "//table[@class='table noAdjust table-bordered table-hover tree-check-table no-footer dataTable DTFC_Cloned']//i[@xpath='1']"
to.addProperty('xpath', ConditionType.EQUALS, xpath)
while(WebUI.verifyElementPresent(to, 5)){
WebUI.click(to)
WebUI.delay(1)
}
Above code not working for me
but Using JS click is working fine
clickUsingJS(to,timeout)
Thank you for your help