Suppose we are in login page and then we clicked on forget password link. Now we are in forget password page and we want to go back to the login page.
Let's see how can we go back to the previous web page.
driver.navigate().back() - This command is used to go previous page.
Back To The Previous Web Page Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class SeleniumBack { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.navigate().to("http:// www.facebook. com"); WebElement element = driver.findElement(By.linkText("Forgot your password?")); element.click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.navigate().back(); } }