How to Verify Page Title in selenium Using Java

.

Handling Page Title In Selenium Webdriver 

How to verify page title in selenium webdriver using java

How To Get the Page Title in Selenium Webdriver?

driver.getTitle()
By using the getTitle() Method We can get the title of a webpage in selenium

Syntax-
The Basic Syntax for getting a title  in selenium is given below

driver.getTitle()


Selenium Code To 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[] argsthrows InterruptedException {
              // TODO Auto-generated method stub
             
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver drivernew ChromeDriver();
              driver.manage().window().maximize();
              driver.get("https://www.facebook.com/");
             
              //Get The Title
              String titl=driver.getTitle();
              
              System.out.println( titl);
              }

                    

}



How to Verify Page title in selenium Webdriver Using Java
To verify that the actual page title of the webpage is the same as the expected page title just follow the below code.

Selenium Code:

package automationtesting;

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

public class Gettitle {
       public static void main(String[] argsthrows InterruptedException {
              // TODO Auto-generated method stub
             
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver drivernew 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");
                     }
              }

                    

}

Example - Selenium Find page title

WebDriver driver = new ChromeDriver(); 
driver.get("https://www.qaacharya.in"); 
System.out.println(driver.getTitle());

Above Java Selenium code. It opens Qa acharya Chrome browser and then prints the page title to the console.


Example to page title 




Hope!!! The above Tutorial on "How to Get the Page Title in Selenium" is helpful for you...

Team, 
QA acharya

Tags : Page title in selenium, get page title in selenium webdriver, Getting page title of web page using selenium webdriver. how to verify page title in selenium webdriver


.

Post a Comment

0 Comments