Page titles may look simple, but they play a powerful role in UI testing. Every time you land on a web page, the browser title tells you where you are. That same logic applies to automation.
With Selenium WebDriver, you can get the page title to confirm if your test is on the right screen. If you're trying to validate navigation, this ability to get title in Selenium helps confirm that the application behaves as expected.
In this article, we’ll walk you through:
Let’s get started.
Selenium WebDriver provides a simple method to get the title of the current page. You can use it to confirm that the browser has loaded the right content before continuing with your test.
The method is straightforward. In Java, it’s called getTitle. In Python, you can use the title property. Both return the text displayed in the browser’s title bar or tab.
You can use this value for logging, for conditional logic, or to validate that a page has loaded successfully after a navigation event. When you get title in Selenium, you add an extra layer of confidence to your automation flow.
Getting the page title in Selenium is a quick way to confirm that your test is on the right path. It gives you a clear checkpoint without requiring complex element lookups or deep DOM interaction.
Page title checks are simple but powerful. They help ensure that your automation script is behaving as expected during key navigation steps. Here are some practical reasons to get title in Selenium:
These checks are lightweight. They add almost no overhead to your test but offer strong validation where it matters. That makes the page title one of the most accessible tools in your Selenium toolbox.
Let’s walk through two quick examples to show how to get title in Selenium. These scripts will help you verify the current page title using Java and Python. You can run them as part of your existing test suite or as a standalone check.
Here is how it works in Java:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class GetTitleExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");
String title = driver.getTitle();
System.out.println("Page title is: " + title);
driver.quit();
}
}
This code launches Chrome, navigates to Katalon, gets the page title, and prints it. You can replace the URL to match your own test case.
Now let’s see how to get the page title in Python:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://katalon.com")
title = driver.title
print("Page title is:", title)
driver.quit()
Both examples follow the same pattern. Open a browser, navigate to a page, retrieve the title, and print the result. This is the fastest way to get title in Selenium and use it for validation or debugging.
Getting the title is useful. Verifying the title adds real value. You can easily turn your title check into an assertion, making sure the browser lands on the expected page at the right time.
In Selenium, you can compare the actual title to a known string or check whether it includes specific text. This works well with test frameworks like TestNG and PyTest where assertions are part of the test flow.
Here’s how to assert the exact title in Java using TestNG:
import org.testng.Assert;
String actualTitle = driver.getTitle();
String expectedTitle = "Katalon | Simplify Web Testing";
Assert.assertEquals(actualTitle, expectedTitle);
Now let’s do a contains check in Python using PyTest:
def test_page_title(driver):
driver.get("https://katalon.com")
assert "Katalon" in driver.title
Assertions like these make your tests more meaningful. They help confirm that navigation works and that users land where they should. When you get title in Selenium, pair it with a smart assertion and use it as a real validation step.
Most of the time, getting the page title in Selenium works instantly. But in a few situations, you may need to add a little more handling to keep your test smooth and reliable. Here are a few scenarios where extra care helps.
These patterns are easy to manage once you identify them. A simple wait or a quick switch keeps your title checks reliable even in complex flows. When you get title in Selenium, use it alongside best practices for handling modern web behaviors.
When you get title in Selenium, it gives you a fast checkpoint in your test flow. Used well, it can improve both clarity and stability. Follow these habits to make the most of title checks in your automation strategy.
These guidelines help you treat title checks as a fast and dependable signal. The getTitle method in Selenium works best when it supports a larger test flow, not when it carries all the logic alone.
Katalon is a complete automation solution built on top of Selenium. It gives you the power of WebDriver with a user-friendly interface and smarter tools that make test creation and maintenance easier. You can use Katalon to get page titles, run validations, and manage results across any environment.
With Katalon, you don't have to write every test from scratch. You can build title verification tests using a low-code approach, while still keeping full control when needed. That balance makes Katalon a strong fit for both beginners and advanced teams.
Katalon takes what you can do with Selenium and gives it structure, speed, and scale. It helps you get title in Selenium and go further with less effort and more clarity.
To start learning, visit the Katalon Docs for tutorials or explore courses at the Katalon Academy.