How to obtain the page title using Selenium webdriver?
We can obtain the page title using 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
package RK1.Building_a_selenium_project;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class PageTitle {
public static WebDriver wd;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "F:\\Work Environment\\MyProject\\chromedriver.exe");
wd = new ChromeDriver();
//application launch
wd.get("https://www.testingbuddy.co.in/");
wd.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
wd.manage().window().maximize();
// getTitle() to obtain page title
String title = wd.getTitle();
System.out.println(wd.getTitle());
System.out.println(wd.getCurrentUrl());
wd.quit();
}
}