public class UrlTesting {
public static void main(String[] args) throws IOException, BiffException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Jatin\\Downloads\\chromedriver_v83\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
File excel = new File("C:\\Users\\Jatin\\Desktop\\Worksheet.xls");
FileInputStream fi = new FileInputStream(excel);
Workbook wb = null;
wb = Workbook.getWorkbook(fi);
Sheet s = wb.getSheet(0);
System.out.println(s.getRows());
// driver.get(https://www.google.com/);
for(int row=0; row <=s.getRows();row++)
{
String Urllist = s.getCell(0, row).getContents();
System.out.println("Url list - " + Urllist);
List<WebElement> linkElements = driver.findElements(By.tagName("a"));
String[] linkTexts = new String[linkElements.size()];
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
int j = 0;
for (WebElement e : linkElements)
{
linkTexts[j] = e.getText();
j++;
}
//test each link
for (String t : linkTexts)
{
if (t != null && !t.isEmpty())
{
driver.findElement(By.linkText(t)).click();
String title;
title=driver.getTitle();
if(title.contains("404"))
System.out.println(t + " the link is not working");
else
System.out.println(t + "is working");
}
}
}
}
}
/* console o/p: ChromeDriver was started successfully. May 30, 2020 8:45:18 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C 5 Url list - https://www.example.com/ Url list - https://www.example.com/ Url list - https://www.example.com/ Url list - https://www.example.com/ Url list - https://www.example.com/ Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356) at UrlTesting.main(UrlTesting.java:47) */
Aucun commentaire:
Enregistrer un commentaire