Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothtechsolutions@gmail.com
Vinoth Tech Solutions
  • Home
  • Tutorials
  • Free Complete QA Video Courses
    • Cypress Automation
    • Cucumber BDD Framework
    • JavaScript for Playwright & Cypress Automation
    • API Manual and Automation Testing using SoapUI
    • Appium 2.0 Mobile Automation
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Playwright Course Curriculum
  • About Me
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • Tech Events & Sessions
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • XPath Demo Page
    • Python JS Online Compiler
    • Python Tutorials
  • Home
  • Tutorials
  • Free Complete QA Video Courses
    • Cypress Automation
    • Cucumber BDD Framework
    • JavaScript for Playwright & Cypress Automation
    • API Manual and Automation Testing using SoapUI
    • Appium 2.0 Mobile Automation
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Playwright Course Curriculum
  • About Me
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • Tech Events & Sessions
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • XPath Demo Page
    • Python JS Online Compiler
    • Python Tutorials
View Categories
  • Home
  • Tutorials
  • Selenium Automation Testing
  • Browser Navigation Commands in Selenium

Browser Navigation Commands in Selenium

Browser Navigation Commands in Selenium

Selenium WebDriver provides methods to navigate through browser history, refresh pages, and open URLs. These commands help simulate user actions like going back, forward, or reloading a page.

CommandSyntaxPurpose
Alternative URL Loadingdriver.navigate().to(“url”);Same as get(), but allows chaining with other navigation commands.
Go Backdriver.navigate().back();Navigates to the previous page in browser history.
Go Forwarddriver.navigate().forward();Navigates to the next page in browser history (if available).
Refresh Pagedriver.navigate().refresh();Reloads the current webpage.

Sample Program

📄
filename.js
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class BrowserNavigationDemo {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();        

            // 1. Load initial page (Google)

            driver.get("https://www.google.com");

            System.out.println("Loaded: " + driver.getTitle());

            // 2. Navigate to Amazon (alternative to get())

            driver.navigate().to("https://www.amazon.com");

            System.out.println("Navigated to: " + driver.getTitle());

            // 3. Go back to Google

            driver.navigate().back();

            System.out.println("Went back to: " + driver.getTitle());

            // 4. Go forward to Amazon

            driver.navigate().forward();

            System.out.println("Went forward to: " + driver.getTitle());

            // 5. Refresh current page

            driver.navigate().refresh();

            System.out.println("Refreshed: " + driver.getTitle());

            // 6. Maximize window (Bonus)

            driver.manage().window().maximize();

            // Close the browser

            driver.quit();

        }

}

How to do Title and Current URL Validation in Selenium ?

1. getTitle() Method

Purpose: Fetches the title of the current webpage.

What it returns:

  • A String containing the text between the HTML <title> tags.
  • Example: If the page title is “Google”, driver.getTitle() returns “Google”.

Common Uses:

  • Verify if the browser landed on the expected page.
  • Log the page title for debugging.

Conditional logic (e.g., proceed only if the title matches).

2. getCurrentUrl() Method

Purpose: Fetches the full URL of the current webpage in the browser’s address bar.

What it returns:

  • A String with the complete URL (e.g., “https://www.google.com/search?q=selenium”).

Common Uses:

  • Confirm navigation to the correct URL (e.g., after clicking a link).
  • Check for redirects or URL parameters.
  • Validate secure connections (e.g., https://).

Sample Example:

📄
filename.js
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class ValidationDemo {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();

            // Navigate to page

            driver.get("https://www.google.com");

            // Title Validation

            String actualTitle = driver.getTitle();

            if (actualTitle.equals("Google")) {

                System.out.println("✓ Title correct: " + actualTitle);

            } else {

                System.out.println("✗ Title mismatch. Expected 'Google', Got: " + actualTitle);

            }

            // URL Validation

            String currentUrl = driver.getCurrentUrl();

            if (currentUrl.startsWith("https://www.google.")) {

                System.out.println("✓ Valid Google URL: " + currentUrl);

            } else {

                System.out.println("✗ Invalid URL: " + currentUrl);

            }            

}

Note: For titles/URLs that change (e.g., timestamps), use contains() or regex instead of exact matches.

Selenium Automation Testing
What are your Feelings

Share This Article :

  • Facebook
  • X
  • LinkedIn
How to launch the browsers ? Handling the textbox and button using selenium
© 2025 V-Tech Solutions Ltd (UK), Reg. No: 16489105