Friday 11 November 2016

Verify Title of a webpage using selenium webdriver script


Today we will be learning that how we can verify a title of a webpage using script.There can be a testcase where we have to verify the title of a webpage so for this we can use IF condition and functions of String class as well.



SCRIPT FOR VERIFYING TITLE OF A WEBPAGE


import java.io.File;
import org.openqa.selenium.WebDriver;

public class verifytitle
{
public static void main(String[] args)
{

WebDriver driver = new FirefoxDriver();
String baseurl = "http://seleniumtestingcom.blogspot.in/";
                String expectedtitle = "Automation Testing";
                String actualtitle = "";

              driver.get(baseurl);
             // get the actual value of the title
             actualtitle = driver.getTitle();

            if (actualtitle.contentEquals(expectedtitle))
           {
                  System.out.println("Test Passed!");
            }
           else
           {
                  System.out.println("Test Failed");
           }    
              driver.close();
}


}

In this case we will be getting Test Passed as an output

2 comments: