How to fetch all links and click those links one by one using Selenium WebDriver

后端 未结 6 1329
深忆病人
深忆病人 2021-01-05 22:59

I am using Selenium WebDriver with java.

I am fetching all links from webpage and trying to click each link one by one. I am getting below error:

6条回答
  •  星月不相逢
    2021-01-05 23:26

    //extract the link texts of each link element
            for (WebElement elements : linkElements) {
                linkTexts[i] = elements.getText();
                i++;
            }
    
            //test each link
            for (String t : linkTexts) {
                driver.findElement(By.linkText(t)).click();
                if (driver.getTitle().equals(notWorkingUrlTitle )) {
                    System.out.println("\"" + t + "\""
                            + " is not working.");
                } else {
                    System.out.println("\"" + t + "\""
                            + " is working.");
                }
                driver.navigate().back();
            }
            driver.quit();
        }
    

    For complete Explanation Read This POST

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题