Vasanth
Vasanth

Reputation: 494

HTML Parsing library in java

I am working on Selenium with java client. I am getting the Html as the string using the method driver.getPageSource() .

Can you please suggest to me, do we have any open source which is used to convert the Html to Java Object?

Based on that above question, I am expecting functionality like below:

Note: As of now I am checking the expected data using the contain(), indexOf(), lastIndexOf() methods.

Regards, Vasanth D

Upvotes: 0

Views: 442

Answers (1)

Petr Janeček
Petr Janeček

Reputation: 38444

Don't do that! Selenium does it for you (and much more).

Once you're on the page you wanted to get to, you can get all the data you need:

/** Maps IDs of all textboxes to their value attribute. */
public Map<String,String> getTextBoxIds() {
    Map<String,String> textboxIds = new HashMap<>();

    // find all textboxes
    List<WebElement> textboxes = driver.findElements(By.cssSelector("input[type='text']"));
    // map id of each textbox to its value
    for (WebElement textbox : textboxes) {
        textboxIds.put(textbox.getAttribute("id"), textbox.getAttribute("value"));
    }

    return textboxIds;
}

and so on and so forth. Look at Selenium's documentation to find out more.

Also, JavaDocs.

Upvotes: 3

Related Questions