Results 1 to 8 of 8
  1. #1
    liquidwind is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Help sending a file to a web page.

    Hi, a I am new to java (been Reading for 2 days now), and have almost no knowledge on programming (I am a Mechanical Engineer).

    The problem I have is that I have to upload 5,000 files to a web page (each one is name B001400XXXX.pdf in consecutive order).

    I have managed to access the web page and select a few form elements using watij, but I am having a hard time sending my pdf file to the server. This is what I have so far:

    Java Code:
    
    import org.watij.webspec.dsl.WebSpec;
    
    public class NewClass {
     
        
        public static void main(String[] args)  {
     
            
            WebSpec spec = new WebSpec().mozilla();
    spec.open("http://207.248.177.30/gestion/login2.asp");
    spec.find.input().with.name("txt_usuario").set.value("UserName");
    spec.find.input().with.name("txt_psw").set.value("Password");
    spec.find.input().with.type("submit").with.value("Generar Acceso").click();
    
    
    
    int B00 = 14002471;  // This is where I plan to put a for loop so I can declare the files I want to upload (from XXXX to XXXX). I choose this file for running tests only. 
    
    spec.open("http://207.248.177.30/gestion/selecciona_enviados.asp?id_doc="+ B00); 
    
    spec.find.input().with.name("rad_asignado").with.value("3413").click(); // This is where I select my name from a list. 
    
    
    spec.find.input().with.type("submit").with.value("Continuar...").click();
    
    spec.open("http://207.248.177.30/gestion/scan.asp?id_doc="+ B00);
    
    spec.record.file().set("C:\\Users\\Victor\\Documents\\NetBeansProjects\\WebInteractionTest\\B0014002471.pdf").ok(); //This is where I messed up. It won´t send any file to the system.
    spec.find.input().with.type("file").click(); //

    I have looked into the page source code to see how it was made and this is what I got:



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>

    </title></head>
    <body>
    <form method="post" action="/fileupload/fileupload.aspx?RUTA=TIT%2f&amp;ID_DOC=14002471&am p;ssid=9103" id="form1" enctype="multipart/form-data">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQ3MjU2NTMzMQ9kFgICAw8WAh4HZW5jdHlwZQUTbXV sdGlwYXJ0L2Zvcm0tZGF0YWRkMj2kQ8q+T7YeEjTcVAs5dgcOr v95jiUUhibEd5jDZRk=" />

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKAvNCDDALeyN+CDPLcg28Q5jU+K1WAIIj20Hfrsuz9yZl V2BMQBa+gbYdN" />
    <div>
    <h4>Seleccionar Archivo:</h4>

    <input type="file" name="FileUpload1" id="FileUpload1" />

    <br /><br />

    <input type="submit" name="UploadButton" value="Cargar Archivo" id="UploadButton" />

    <hr /><br />
    <span id="UploadStatusLabel"></span>
    <br />

    </div>
    </form>
    </body>
    </html>

    Thanks a lot for the help!
    Last edited by liquidwind; 02-20-2014 at 05:59 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Help sending a file to a web page.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    I have never seen the package the code imports. Is there a forum site for uses of that package?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    liquidwind is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help sending a file to a web page.

    Thank you for your suggestion. I did not know I had to put code tags. It looks much better!

    The forum I used is watij.com. The package is meant to interact with web pages, or that is what I think. It worked pretty well for selecting options in forms and interacting with buttons, but I could not figure out how to send files to a web form.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    922
    Rep Power
    2

    Default Re: Help sending a file to a web page.

    Before going this route I would consider these options:
    - Call their IT department and get SSH or (S)FTP access to the server
    - Copy everything on a USB stick/CD and take it/ship it to their IT department.

    If that all fails, you could code your way in I guess. You say you are having a hard time, but you didn't mention what the problem is. By looking at the code, we don't either. So post some stacktraces or other errors you get.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,684
    Rep Power
    5

    Default Re: Help sending a file to a web page.

    I don't know what this webspec is, but I highly recommend you to use Apache HttpClient for these kind of tasks. Plenty of copy/pastable example programs too if you download the source.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    liquidwind is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help sending a file to a web page.

    Thanks, I will give it a try!

  7. #7
    liquidwind is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help sending a file to a web page.

    Thanks for your reply.

    I tried that, but IT department told me they were really busy and could not help me.
    The program is supposed to give information on the file and then upload it. So far, it opens a web page, logs in and sends the information required for the file. The problem is that when it gets to the part where it is supposed to send the file nothing happens. I was expecting to see the file path filled out in the form or the message that my file has been sent, but I see nothing happening.


    This is the error I got in NetBeans:

    run:
    log4j:WARN No appenders could be found for logger (com.jniwrapper.DefaultLibraryLoader).
    log4j:WARN Please initialize the log4j system properly.
    java.io.IOException: Cannot run program "null\autoit\file_ok.exe": CreateProcess error=2, El sistema no puede encontrar el archivo especificado
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :1041)
    at java.lang.Runtime.exec(Runtime.java:617)
    at java.lang.Runtime.exec(Runtime.java:450)
    at java.lang.Runtime.exec(Runtime.java:347)
    at org.watij.webspec.dsl.dialog.Dialog.runScript(Dial og.java:59)
    at org.watij.webspec.dsl.dialog.File.ok(File.java:11)
    at NewClass.main(NewClass.java:34)
    Caused by: java.io.IOException: CreateProcess error=2, El sistema no puede encontrar el archivo especificado
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
    at java.lang.ProcessImpl.start(ProcessImpl.java:136)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :1022)
    ... 6 more
    Exception in thread "main" java.lang.RuntimeException: Expectation failed: Element should exist before calling CLICK
    at org.watij.webspec.dsl.Tag.shouldExist(Tag.java:332 )
    at org.watij.webspec.dsl.Tag.click(Tag.java:260)
    at org.watij.webspec.dsl.Tag.click(Tag.java:255)
    at NewClass.main(NewClass.java:35)
    BUILD STOPPED (total time: 1 minute 14 seconds)


    Thanks a lot!
    Last edited by liquidwind; 02-20-2014 at 04:52 PM.

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    922
    Rep Power
    2

    Default Re: Help sending a file to a web page.

    The null in "null\autoit\file_ok.exe" is probably not supposed to be there. Find out how this path is built and why this part is null.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

Similar Threads

  1. Sending a file to a web page using POST method
    By FlyNn in forum Advanced Java
    Replies: 7
    Last Post: 01-31-2014, 02:28 PM
  2. Replies: 4
    Last Post: 09-11-2012, 09:41 AM
  3. Replies: 8
    Last Post: 02-18-2010, 12:54 PM
  4. Sending text to a web page
    By shyameni in forum Advanced Java
    Replies: 2
    Last Post: 10-08-2009, 07:14 AM
  5. Sending text to a web page
    By shyameni in forum Advanced Java
    Replies: 0
    Last Post: 10-07-2009, 06:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •