Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Selenium Automation Testing

  • Introduction to Automation Testing
  •  Introduction to Selenium
  • Advantages and Disadvantages of Selenium WebDriver
  •  Locators in Selenium
  • How to launch the browsers ? 
  • Browser Navigation Commands in Selenium
  •  Handling the textbox and button using selenium
  • Handling the radio button and checkbox using selenium
  •  Handling the drop downs and multi-select dropdown
  • Validate the text validation and attributes values. 
  • Handling Alert Popup
  • Handling iFrames
  • Handling Multiple Browsers or Tabs
View Categories
  • Home
  • Tutorials
  • Selenium Automation
  • 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

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:

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
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105