Navigate to previous page using Selenium



  • I know there's a

    driver.navigate().back()
    

    but that's not what I'm looking for.

    Let's say a user is on PageA, they click on a submit button which takes them to a submit page. On that page, there are two buttons: change selection and confirm. Confirm takes them to the next page, but change selection takes them back to the page they were on.

    It's not always going to be PageA, a user can be on PageB, PageC, etc. So, I was wondering if there is a way to return the PageFactory of whatever page the user was previously on? I haven't been able to find anything so far



  • You can use JavaScript to go back one step in the history of the browser, this should bring you back on the previous page.

    driver.executeScript("window.history.go(-1)");
    

    See using JavaScript with Selenium and JavaScript History functions links.

    Also see this thread about issue and difference with navigate.back()



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2