# 5.5. Web Table

```java
public class TableTest {
    WebDriver driver;
    List<Person> persons;
    @BeforeClass
    void setup(){
        driver = new ChromeDriver();
        driver.get("https://the-internet.herokuapp.com/tables");
        List<WebElement> rows = driver.findElements(By.xpath("//table[@id='table1']/tbody/tr"));

        persons = rows.stream()
                .map(this::toPerson).collect(Collectors.toList());

    }

    @Test
    void largestDuePerson(){
        Person largestDuePerson = persons
                .stream()
                .max(Comparator.comparing(Person::getDue))
                .orElseThrow(NoSuchElementException::new);

        Assert.assertEquals(String.format("%s %s", largestDuePerson.getLastName(), largestDuePerson.getFirstName()), "Jason Doe");
    }

    @Test
    void smallestDuePerson(){
        Person smallestDuePerson = persons
                .stream()
                .min(Comparator.comparing(Person::getDue))
                .orElseThrow(NoSuchElementException::new);

        Assert.assertEquals(String.format("%s %s", smallestDuePerson.getLastName(), smallestDuePerson.getFirstName()), "Jason Doe");
    }

    /**
     * element is a row in table
     * @param element
     * @return
             */
    private Person toPerson(WebElement element) {
        String lastName = element.findElements(By.tagName("td")).get(0).getText();
        String firstname = element.findElements(By.tagName("td")).get(1).getText();
        String email = element.findElements(By.tagName("td")).get(2).getText();
        float due = Float.parseFloat(element.findElements(By.tagName("td")).get(3).getText().trim().replace("$", ""));
        String website = element.findElements(By.tagName("td")).get(4).getText();
        return new Person(firstname, lastName, email, website, due);
    }

    @AfterClass
    void tearDown(){
        driver.quit();
    }
}
```

### �- add lombok dependency to your pom file

```markup
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.20</version>
</dependency>
```

�**Person class**

```java
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

@Getter @AllArgsConstructor
@Data
public class Person {
    private final String lastName;
    private final String firstName;
    private final String email;
    private final String website;
    private final float due;
}
```

�


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tvn.gitbook.io/selenium-java/examples/web-table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
