How to retrieve all the links from a web table and print them in sorting order.

Default Asked on June 15, 2016 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    List<WebElement> linkElements = driver.findElements(By.tagName(“a”));

    String[] linkTexts = new String[linkElements.size()];

    int i = 0;

    //extract the link texts of each link element

    for (WebElement e : linkElements) {

    linkTexts[i] = e.getText();



    Use Collections.sort(linkElements) to print in sorted order

    Train Answered on June 15, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.