Reputation: 353
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.
Upvotes: 2
Views: 10685
Reputation: 5667
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();
Upvotes: 4