Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Navigation Command in Selenium Webdriver,Selenium Webdriver Tutorial:-

It is used to navigate from one web page to another without any action(hyperlink, button click)

Selenium Web Driver provide multiple navigation command to perform the operation.

1) navigate().to() :-  it is used to navigate particular url of web page according to condition

WebDriver driver= new ChromeDriver();
driver.navigate().to("http://shivaconceptsolution.com/test.html");


2)  driver.navigate().back(); :-  it is used to press back button of web browser


3)  driver.navigate().forward():-  It is used to press forward button of web browser


4)  driver.navigate().refresh():-  It is used to refresh current web content of web pages.


Example create automation script to find out total working hyperlink and broken link.

Solution:-
package scs;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class CheckHyperlink {

public static void main(String[] args) {
int a=0,b=0;
System.setProperty("webdriver.chrome.driver","c://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://eroomrent.in/index.php");
List<WebElement> ele = driver.findElements(By.tagName("a"));
Iterator it = ele.iterator();
ArrayList arrlist = new ArrayList();
while(it.hasNext())
{
WebElement e =(WebElement)it.next();
String u =e.getAttribute("href");
if(u.equals("") || u.equals("#"))
{
a++;
}
else
{
b++;
}
arrlist.add(u);
System.out.println(u);
}
for(Object o: arrlist)
{
driver.navigate().to(o.toString());
driver.navigate().back();
driver.navigate().refresh();
}
System.out.println("Total Hyperlinks are "+ele.size());
System.out.println("Total non Working Hyperlinks are "+a);
System.out.println("Total working Hyperlinks are "+b);

}

}





Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post