Selenium WebDriver - Get Domain Name Using JavascriptExecutor

You necessitate electrical flow software spider web application's page URL when you lot accept to compare it amongst your expected URL. You tin create it using WebDriver basic functioning ascendency driver.getCurrentUrl();. This method nosotros accept seen in my Previous Post. If you lot remember, nosotros tin exercise "storeLocation" ascendency to driblet dead electrical flow software spider web application's page URL inwards selenium IDE software testing tool. Main role of this ship service is to explore how to get domain refer inwards webdriver. So if you lot wants to store application's domain name hence you lot necessitate to use JavascriptExecutor inwards your software seek case.

Look here, software application's domain refer is dissimilar than the electrical flow page URL.

If my electrical flow page URLThen
My domain refer is = only-testing-blog.blogspot.in

Let me supply you lot uncomplicated illustration of how to driblet dead electrical flow software spider web application's page URL using driver.getCurrentUrl(); together with how to driblet dead domain refer using JavascriptExecutor.

Example : Get electrical flow URL of page together with domain refer inwards selenium webdriver
Copy bellow given @Test method role of driblet dead current software spider web application's page URL using javascript illustration together with supervene upon it amongst the @Test method role of illustration given on THIS PAGE(Note : @Test method is marked with pink color in that linked page).


@Test  world void seek ()   {     String CurrentURL = driver.getCurrentUrl();   System.out.println("My Current URL Is  : "+CurrentURL);      //Get together with shop domain refer inwards variable   JavascriptExecutor javascript = (JavascriptExecutor) driver;   String DomainUsingJS=(String)javascript.executeScript("return document.domain");     System.out.println("My Current URL Is  : "+DomainUsingJS);  }

(View more Javascript examples inwards selenium webdriver)

In higher upward example, 1st ii syntax volition driblet dead together with impress electrical flow page URL. Last iii syntax volition driblet dead domain refer using javascript together with volition impress it inwards console.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post