I am using Selenium with Java, when I am trying to hit "forgot password" on the page I am testing, Selenium is inserting the inputs on the previous page and then going to the next page:
driver.findElement(By.xpath("//input[@type='email']")).sendKeys("email");
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("password");
driver.findElement(By.className("btn-primary")).click();// -> here it should take us to another page and insert below data, but it is inserting the data on the page and then executing this line and moving to the next page
System.out.println(driver.findElement(By.cssSelector("span.text-with-icon")).getText());
driver.findElement(By.linkText("Forgot Password")).click();
driver.findElement(By.xpath("//input[@type='email']")).sendKeys("email");
When I will use driver.get("https...") it is working fine and taking me to the next page, inserting the data in the proper orde, but I want to hit the URL with "forgot password" and insert data without giving the exact address.