Navigation
interface Navigation {
void back();
void forward();
void to(String url);
void to(URL url);
void refresh();
}
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class NavigationExample1 {
public static void main(String[] args) throws Exception {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to("https://www.w3schools.com/html/default.asp");
Thread.sleep(1000);
System.out.println(driver.getCurrentUrl());
driver.findElement(By.xpath("//a[text()='Next ❯']")).click();
Thread.sleep(1000);
System.out.println(driver.getCurrentUrl());
driver.findElement(By.xpath("//a[text()='Next ❯']")).click();
Thread.sleep(1000);
System.out.println(driver.getCurrentUrl());
driver.navigate().back();
Thread.sleep(1000);
System.out.println(driver.getCurrentUrl());
driver.navigate().forward();
Thread.sleep(1000);
System.out.println(driver.getCurrentUrl());
driver.navigate().refresh();
Thread.sleep(1000);
driver.quit();
}
}