Sunday, 19 February 2017

Selenium Webdriver 6 - getCurrentUrl() , getPageSource() & getTitle()

Few basic and important browser functions are explained in this session.

1. String getCurrentUrl() : Get a string representing the current URL that the browser is looking at.
2. String getPageSource() : Get the source code of page.
3. String getTitle() : Get the title of the current page.

Note : All these above method returns String value.

Program :

package shirageri.blog;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class HelloBrowser7 {

public static void main(String[] args)
{

String URL = "http://127.0.0.1:88/login.do";

WebDriver driver = new FirefoxDriver();

driver.get(URL);

//1st - getCurrentUrl()
String currentUrl = driver.getCurrentUrl();
System.out.println("Current URl : "+currentUrl);
System.out.println("------------------------------------------");

//2nd - getTitle()
String pageTitle = driver.getTitle();
System.out.println("Page Title : "+pageTitle);
System.out.println("------------------------------------------");

//3rd - getPageSource()
String pageSource = driver.getPageSource();
System.out.println("Page Source : "+pageSource);
System.out.println("------------------------------------------");
}
}


No comments:

Post a Comment