How to get the web page title from selenium webdriver?
Okay, What i think you're looking for is this
import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver; public class imsclass1 { static WebDriver driver; String actualTitle; @Test public void test() { driver.get("http://www.google.com"); actualTitle = driver.getTitle(); System.out.println("ActualTitle is " + actualTitle ); } @BeforeClass public static void Beforeclass() { driver = new FirefoxDriver(); } @AfterClass public static void Afterclass() { driver.quit(); }}
How this works:
Driver.get Goes to the page.
Driver.getTitle gets the title of the page.
System.out.println("ActualTitle is " + actualTitle) prints the string "ActualTitle is " + the variable to the console.
hope this helps,
Just change code as per following :
driver.get("http://www.google.com");actualTitle = driver.getTitle();System.out.println("ActualTitle is :" + actualTitle );
Above will print title in console.. You have not added variable in print which storing actual title value and also you using wrong method to get title so you are not getting title.