Get page title with Selenium WebDriver using Java.


We can get the page title with Selenium webdriver. The method getTitle() is used to obtain the present page title and then we can get the result in the console.

Syntax

t = driver.getTitle();

Let us find the title of the current page. We shall get About Careers at Tutorials Point – Tutorialspoint as output.

Example

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;

public class PageTitle{
   public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
      // getTitle() to obtain page title
      System.out.println("Page title is : " + driver.getTitle());
      driver.close();
   }
}

Output

Updated on: 18-Sep-2020

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements