GetDomain Name Using Java Script



public class getDomainName {

WebDriver  driver;
@Test
public void DomainName()
{

driver=new FirefoxDriver();
driver.get("https://www.google.com");
String CurrentUrl = driver.getCurrentUrl();
 System.out.println("My Current URL Is  : "+CurrentUrl);

//type casting driver object in javascript
 JavascriptExecutor javascript1=(JavascriptExecutor)driver;

 //return domain of current url stores in domainusingjs variable
 String DomainUsingJS=(String)javascript1.executeScript("return document.domain");
 System.out.println("domain name is:"+DomainUsingJS);


}


}

Output:

My Current URL Is  : https://www.google.co.in/?gfe_rd=cr&ei=LjP9VcW9B7Tv8wfK0ICoDQ

domain name is:www.google.co.in

PASSED: DomainName


No comments:

Post a Comment