Read data from web table – Selenium and Java Challenge 10

I have provided an HTML table containing several links, along with a Selenium WebDriver automation script written in Java to perform operations on the table. This program will read data from web table using selenium and Java. You can review the execution output generated by the Selenium script and share your comments.
Click the “Click for solution” button to view the explanation of the output.

package tests;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class SampleProgram10{

WebDriver driver = null;

@Test
public void testMySkills() {
    try {
        driver = new ChromeDriver(); // Using Selenium 4.3
        driver.get("https://www.testingtalkslatest.com/2025/12/10/what-is-the-output-of-the-following-script-selenium-and-java-challenge/");

        WebElement elemTable = driver.findElement(By.id("customLinks"));

        JavascriptExecutor jsx = (JavascriptExecutor) driver;
        jsx.executeScript("arguments[0].scrollIntoView(true);", elemTable);

        List<WebElement> elemsRow = elemTable.findElements(By.tagName("tr"));

        for (WebElement elem : elemsRow) {

            List<WebElement> elemsCol = elem.findElements(By.tagName("td"));

            for (WebElement elemCell : elemsCol) {

                String text = elemCell.getText();
                System.out.println(text);

                if (text.contains("Amazon")) {
                    elemCell.findElement(By.tagName("a")).click();
                    break;
                }
            }
        }
    } catch (Exception ex) {
        System.out.print(ex.getMessage());
    }
}

}

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox , CodesToolbox
Scroll to Top
0
Would love your thoughts, please comment.x
()
x