Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Java how to return the driver back to the previous page

I have two links in pageA. when I click the 1st link it redirects to another page called pageB and do some certain jobs and returns back to pageA. From here it should again click to the 2nd link but instead it says page has reloaded and no cache available.

//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();
  }
}

Here though it it is going back to previous page pageA but unable to pick the 2nd element from for loop for next operation.

Any thoughts on how to make it work.

like image 483
Shibankar Avatar asked Mar 05 '26 07:03

Shibankar


1 Answers

I think that what you want is the equivalent to press the Back button of your browser, right?

If its this, try that:

webDriver.navigate().back();
like image 111
PedroPK Avatar answered Mar 06 '26 20:03

PedroPK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!