简体   繁体   中英

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:

  • getTextBoxIds() - It will list of the all the text box Ids as the HashMap() ids as the key, and value is the TextBox value.
  • getSelectBoxIds()
  • getDivIds()

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

Regards, Vasanth D

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM