Home Ask Login Register

Developers Planet

Your answer is one click away!

Kelper February 2016

Using Selenium + Java robot + Scrapbook to download a complete web page

I'm trying to download a complete web page (including images, css, scipts, etc.) via Selenium, the java robot class and the ScrapBook firefox extension. I first tried the CTRL+S method with robot but doesn't worked because that could not press ENTER. So I decided to install ScrapBook on firefox (there's a method which do not displays the download dialog) and tried it with plain robot class, that worked fine. But I need to use it with selenium for rapid testing. So here is the source code:

package selenium.inexample;

import java.awt.*;
import java.awt.event.KeyEvent;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class SelRobot {

public static void main(String[] args) throws AWTException {

// I use my firefox profile for using scrapbook
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile myprofile = profile.getProfile("default");

    WebDriver driver = new FirefoxDriver(myprofile);

// This is added only for waiting for the page to load

//Robot uses the keyboard for interacting with browser and using scrapbook
    Robot robot = new Robot();  

    for(int i=0; i<5; i++) {


The problem is that scrapbook downloads the page to local\temp\result as a temporal folder, then it deletes all subfolders and files when the session expires. I need it to be downloaded as a permament page inside the firefox profile folder. The robot


Kelper February 2016

I found the solution!!! The problem was that Scrapbook always downloaded the page to the profile folder. When I used Selenium, a temporary Profile was always created, even If I created a new one or used an already existing one. So, I just configured scrapbook to download the page to any other folder diferent to the profile. Just pressed Alt+k, then Tools > Options > Organize. There I just changed the folder of the downloads. That way, selenium doesn't deletes the page because it's not part of it's temp profile data.

Post Status

Asked in February 2016
Viewed 2,250 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life