2

i'm going to rewrite all my tests project, by replacing Selenium by HtmlUnit because i'm not able to get plain text in selenium as i can do with htmlunit using "HtmlPage:asText" method. Getting plain text can help me to verify easily the content of a page, without paying attention of the presence or not of the tags.

For example a plain text like this " One, two three" may correspond to many html source:

<p>One, two three</p> 

or <table> <tr><td>One1</td><td>two</td><td>three</td> </tr></table> or <div><span>One, </span> <span>two, </span> <span>three, </span> </div>

By using HtmlUnit i can write functional test without paying attention of how the actual content will be represented in the html format.

1 Answer 1

4

This will give you only plain text in page

String pageSource=driver.findElement(By.tagName("body")).getText();

Below logic will gives you entire page source.

driver.getPageSource();
1
  • python equivalent: driver.find_element(By.TAG_NAME, 'body').text
    – wisbucky
    Dec 9, 2021 at 9:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.