Stale element reference

Viewed 34

I am trying to check links in the parts of html page, even though I am using the same format with somewhere else there is no problem but with this one in every Object[] data there is a ArrayList inside of it and it was working before but I don't remember what I have changed it.

@Test (dataProvider = "mainPageLinks") public void checkLinks(ArrayList<WebElement> data) throws IOException {
    SoftAssert soft = new SoftAssert();

    for (WebElement a : data) {
        String url = a.getAttribute("href"); //**it shows error here**
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setRequestMethod("HEAD");
        conn.connect();
        soft.assertTrue(conn.getResponseCode() < 400,a.getText() + "          BROKEN LINK");
    }
    soft.assertAll();
}

@DataProvider public Object[] mainPageLinks(){
    Object[] data = new Object[3];
    data[0] = driver.findElements(By.cssSelector(".calendars-inner-div a"));
    data[1] = driver.findElements(By.cssSelector("footer a"));
    data[2] = driver.findElements(By.cssSelector(".fc-daygrid-day-events a"));
    return data;
}
0 Answers
Related