0

I am working on an project. In that, I have to get HTML page source code. For that, I invoke firefox driver using Selenium, and store page source code in String, and then parse using Jsoup

My code worked fine for single url. But when I put my code in testing, where it has to get numbers of URLS one by one, then at the end it throws one exception, and my project fails. Please see the exception and tell me why this occurs, and give me some solution to overcome this Exception.

My selenium code is as follows,

private static FirefoxProfile createFirefoxProfile() {
    File profileDir = new File("/tmp/firefox-profile-dir");
    if (profileDir.exists()) {
        return new FirefoxProfile(profileDir);
    }
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    File dir = firefoxProfile.layoutOnDisk();
    try {
        profileDir.mkdirs();
        FileUtils.copyDirectory(dir, profileDir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return firefoxProfile;
}

// below code in main function (url1 and url2 are two urls )

WebDriver driver = new FirefoxDriver(createFirefoxProfile());
driver.get(url1);
String hml1 = driver.getPageSource();
driver.get(url2);
String hml2 = driver.getPageSource();
driver.close();

Exception

[WARNING] 
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows: 
    null
    Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:122)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:188)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:96)
        at XXX.YYY.ZZZ.Template_Matching.Scroll_down.processing(Scroll_down.java:334)
        at XXX.YYY.ZZZ.Template_Matching.Scroll_down.main(Scroll_down.java:472)
        ... 6 more
    Caused by: org.openqa.selenium.firefox.UnableToCreateProfileException: java.io.IOException: There is not enough space on the disk
    Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:453)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
        ... 14 more
    Caused by: java.io.IOException: There is not enough space on the disk
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(FileOutputStream.java:282)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
        at org.openqa.selenium.io.Zip.unzipFile(Zip.java:171)
        at org.openqa.selenium.io.Zip.unzip(Zip.java:152)
        at org.openqa.selenium.io.FileHandler.unzip(FileHandler.java:54)
        at org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:81)
        at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:58)
        at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)
        at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:469)
        at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:447)
        ... 15 more
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 20:49:03.625s
    [INFO] Finished at: Thu Apr 18 10:47:12 IST 2013
    [INFO] Final Memory: 12M/163M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project Template_Matching: An exception occured while executing the Java class. null: InvocationTargetException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows:
    [ERROR] null
    [ERROR] Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    [ERROR] System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    [ERROR] Driver info: driver.version: FirefoxDriver: java.io.IOException: There is not enough space on the disk
    [ERROR] Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    [ERROR] System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    [ERROR] Driver info: driver.version: FirefoxDriver
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
devsda
  • 4,112
  • 9
  • 50
  • 87
  • 1
    How many scripts(similar to this) you are running in the project? The exception say two thing: 1) Cannot connect to your firefox and 2.) There is not enough space on the disk. So, Make sure before completing the project your firefox browser instance doesn't get closed somewhere else in your scripts and try limiting number of scripts in your projects if you have low disk space. – me_digvijay Apr 18 '13 at 06:39
  • 1) Why it not connects to firefox, as internet is working? 2) Space is enough , i.e., 84 GB gree in my hardDisk. Yes, browsers is closed everytime, after getting page source of any url, you can see above code. I think there is some problem in above `createFirefoxProfile` module, can you help me in that, please. – devsda Apr 18 '13 at 06:51
  • Yes, Its looks like the problem is in the createProfile method. Take a look on this question. Looks similar to your problem. http://stackoverflow.com/questions/13514338/failed-to-connect-to-binary-firefoxbinary-with-selenium-in-maven – me_digvijay Apr 18 '13 at 06:53
  • Keep a backup of already existing FF profile present in C:\Users\your computer name\AppData\Roaming\Mozilla\Firefox\Profiles and delete them. After this try running your code. Let us know the result. – HemChe Apr 18 '13 at 07:19
  • 1
    @HemChe creats or uses a profile here `C:\tmp\firefox-profile-dir` @devsda clean your directory `C:\tmp\firefox-profile-dir` and check your C:\ free space left. – e1che Apr 18 '13 at 08:01
  • I cleaned that directory, and the space is 85 GB – devsda Apr 18 '13 at 08:11

1 Answers1

0

You probably work on your usb flashdrive or SD card. Check out your hard disk free space and if you aren't working on a peripheral.

e1che
  • 1,241
  • 1
  • 17
  • 34
  • No, I am working on my Desktop having hardDisk 248 GB, and free space is 85 GB. – devsda Apr 18 '13 at 06:36
  • I suggest to you to try with a empty profile. like `FirefoxProfile profile = new FirefoxProfile(); WebDriver driver = new FirefoxDriver(profile);` – e1che Apr 18 '13 at 06:39
  • Actually I made `createFirefoxProfile` function, because it solves the problem of creating new browser instance everytime, it takes lots of time. Can you optimize this module , please? So I can reduce time cost, and also solves this Exception. – devsda Apr 18 '13 at 06:49
  • Where's your profile ? because the `/tmp/firefox-profile-dir` path is false if your want to take it from a hd like `D:\Users\marco\Desktop\dev\tmp\firefox-profile-dir` – e1che Apr 18 '13 at 07:18
  • profile means ? I didn't understand what you said in above comment, can you please ask me in simpler term. I took this above code from here, http://stackoverflow.com/questions/15830334/selenium-takes-lots-of-time-to-get-dynamic-page-of-given-url – devsda Apr 18 '13 at 07:28
  • Have you 2 hard disk ? like C:\ and D:\ – e1che Apr 18 '13 at 07:58
  • No, I have only one hardDisk, i.e., C:/ – devsda Apr 18 '13 at 08:10