我在pageA中有两个链接。当我点击第一个链接时,它会重定向到另一个名为pageB的页面并执行某些特定的工作并返回到pageA。从这里它应该再次点击到第二个链接,但它表示页面已重新加载,没有可用的缓存。
//List of all tickets
for(WebElement ticket: ticketList){
List<WebElement> ticketCells = ticket.findElements(By.tagName('td'));
if(ticketCells.get(4).getText().equalIgnoreCase("Some Text")){
ticketCells.get(2).click(); //Redirects to pageB
.....
do some job
.......
//Finally clicking on the 'SAVE & BACK' button which should return to previous
//page and pick the 2nd ticket from the list of all tickets (1st for loop)
driver.findElement(By.id("save&back")).click();
}
}
虽然它会回到上一页pageA,但无法从for循环中选择第二个元素进行下一步操作。
关于如何使其发挥作用的任何想法。
答案 0 :(得分:1)
我认为您想要的就是按浏览器的 后退 按钮,对吧?
如果是这样,请尝试以下操作:
webDriver.navigate().back();
答案 1 :(得分:0)
@try-catch-finally explained it very clearly. The below code is exactly what you need to handle the error.
for(int i = 0; i <2 ;i++){
ticketList = driver.findElements(selector);
ticket = ticketList.get(i);
List<WebElement> ticketCells = ticket.findElements(By.tagName('td'));
if(ticketCells.get(4).getText().equalIgnoreCase("Some Text")){
ticketCells.get(2).click(); //Redirects to pageB
.....
do some job
.......
//Finally clicking on the 'SAVE & BACK' button which should return to previous
//page and pick the 2nd ticket from the list of all tickets (1st for loop)
driver.findElement(By.id("save&back")).click();
}
}