0

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

4
  • 5
    JSoup? Commented Jun 11, 2013 at 10:53
  • As a clarification: basically you are looking for a library to convert HTML string to typed java objects representing HTML elements. Commented Jun 11, 2013 at 10:54
  • @BackSlash sounds like an answer to me :) Commented Jun 11, 2013 at 10:55
  • ok fine , thanks , i will have look at it . Commented Jun 11, 2013 at 11:00

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Slanec, This what i am expected . i have tested as well , the code is working fine which is given by you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.