How to get the page Title in selenium Webdriver


How to get the page Title in selenium Web driver-

driver.getTitle()

By Using the getTitle() Method We can get the title of page in selenium

Synatx-
The Basic Syntax for get title  in selenium are given below

driver.getTitle()


Selenium code For get the page title using java


package automationtesting;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Gettitle {
       public static void main(String[] args) throws InterruptedException {
              // TODO Auto-generated method stub
             
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver driver= new ChromeDriver();
              driver.manage().window().maximize();
              driver.get("https://www.facebook.com/");
              System.out.println( driver.getTitle());
              //Get The Title
              String titl=driver.getTitle();
              //Verify The Title
              if (titl.equals("Facebook – log in or sign up"))
              {
                     System.out.println("True");
              }
                     else {
                           System.out.println("False");
                     }
              }

                    

}

Post a Comment

0 Comments