Skip to main content

Posts

Showing posts from September, 2013

How to disable flash in FirefoxDriver/ FirefoxProfile / using java in Selenium?

For some tests using selenium automated testing with FirefoxDriver one can create a custom FirefoxProfile and disable flash in it. Here is the code I used for this.                 FirefoxProfile profile= new FirefoxProfile(); profile.setPreference("plugin.state.flash", 0); FirefoxDriver driver = new                                       FirefoxDriver(profile);

How to parse HTML/ extract data from HTML / using Java?

Java has a large set of APIs to parse HTML. To extract data from HTML  and perform any manipulation we should be able to parse it. jsoup provides a very easy to use , powerful and compact API to pare HTML and extract data. It supports DOM, CSS and jquery like selectors. It is designed for all types of HTML and will even parse HTML which is not perfectly valid. Example In this example we fetch BBC Sport , parse it to DOM and then select headlines using css-selector. Document doc = soup.connect(" http://www.bbc.co.uk/sport/0/ ").get();  Elements newsHeadlines = doc.select("#more-news-headlines li"); We can also provide HTML directly in a string.  A detailed documentation is available at jsoup website. You may start from official cook book available here .