Is there any way to save complete web-page using WebDriver?
Currently I do getPageSource() and then put everything into html local file, but saved page is in not good shape (strange characters, no images, all elements offset down)
See below code that I use:
@Test
public void testSomeThing(){
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://google.com");
String pageSource = driver.getPageSource();
writeInFile(System.getProperty("user.dir")+"/target/logs/testPage.html", pageSource);
}
public static void writeInFile(String sFileName, String sTextToWrite){
FileWriter outFile;
General.sendComments("Write to file: " + sFileName);
try {
outFile = new FileWriter(sFileName);
PrintWriter out = new PrintWriter(outFile);
out.print(sTextToWrite);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Could somebody please suggest me the way I can save complete web page in firefox using WebDriver? e.g automatically?
Strange characters might have something to do with the encoding of the written file.
The other problems will probably have to do with the fact that you are loading a static html file for which the relative url’s no longer point to anything. Any javascript, css and image files will be missing.