I’m trying to get elements from the UI and then take some actions over them. What I am trying to do is that, I have 3 buttons and I want to click on each of them.
So, I expect that WebUI.click will work so that, it will click on the first taken element, then second and so. But I am getting error when it tries to click on elem.
I’ve also used TestObject to click an element.
//String xpath = "//div[@class='sc-bdVaJa sc-hwwEjo kIFSBP sc-gZMcBi hgNaev']"
//TestObject to = new TestObject("objectName")
//to.addProperty("xpath", ConditionType.EQUALS, xpath)
but if I will use WebUI.click(to), it will click 3 times on the same object.
Yes, I was afraid of that. Whenever you click something that redirects you (like a link, in your case), any elements you’ve located become “stale”. Your list of links becomes stale in this case. Try copying the part where you get the list of links into your loop as well:
for(WebElements elem in elements) {
elem.click()
WebUI.delay(2)
NavigationService.navigateToPage1()
WebUI.delay(2)
NavigationService.navigateToPage2()
WebUI.delay(2)
elements = DriverFactory.getWebDriver().findElements(By.xpath("//div[@class='sc-bdVaJa sc-hwwEjo kIFSBP sc-gZMcBi hgNaev']"))
}
Well, I declare that xpath what I want outside for statement. In the for statement, I just saying to it, that iteration should be done how much size does that elements have. And in for statement, I declare same xpath again on each iteration.
I really don’t know if this is correct. Well, it works but…