Tuesday, 9 July 2013

Getting Parsed Page Content Using Selenium

There might come several situations where need to extract particular page content using selenium.This is different from getting the page source using 'driver.getPageSource()' which gives raw HTML code.

Suppose we want the entire text from a particular area from a web page Selenium provides an excellent way to do that.

'String required_text=driver.findElement(By.tagName("put the HTML tag here")).getText();'

This gives you the required text of the particular web element.We can also use By.id or By.xpath or other locator strategies whichever works for us.But this usually does the trick.It comes useful when we want the page content for logging purposes, plain text parsing of the required text from the DOM is usually difficult and not recommended. 



No comments:

Post a Comment