0

This is not a duplicate . I have a Selenium solution for this, but I do not prefer using Selenium . I hope somevbody could help me with a HttpUrlConnection code that would deal with this javascript directly rather than finding a work around that pop up using Selenium


On a webpage I have the following link (covered with an image)

     <a .............

     onclick="javascript:downLoad('CAMID(\xxx;)/folder[@name=\'test\']/folder[@name=\'test\']

    /reportView[@name=\'test\']/output[@name=\'test']',

    'spreadsheetML' )" alt="Download" ></a>

Ones I click on this link a pop up window shows up and I can click on the save

How can I get this file programmatically using Java? There must be a way to stream the file without even touching that pop up


So far I am using Selenium and Java Robot object to hit that save button . But I am sure there must be a way to download it directly .

Andrei Vasilev
  • 587
  • 4
  • 14
  • 35
  • The accepted answer to [this SO post](http://stackoverflow.com/questions/1359689/how-to-send-http-request-in-java) should get you started (in a nutshell: use java.net.HttpUrlConnection). – collapsar Mar 28 '14 at 14:31
  • possible duplicate of [Handling a popup window using selenium](http://stackoverflow.com/questions/14939298/handling-a-popup-window-using-selenium) – Aaron Digulla Mar 28 '14 at 14:33
  • Thans I am actually using HttpUrlConnection for simple downloads like a `.pdf` file . . But in this very code , i have a link that pop up a javascript `open save cancel ` window . How can i deal with this very pop up \ – Andrei Vasilev Mar 28 '14 at 14:34

1 Answers1

1

This question tells you how to find the popup window: Handling a popup window using selenium

After that, you can use the usual Selenium API to click the save button.

[EDIT] You can use HttpClient to download from a web server.

The first step would be to download the page with the link. Then, you can use various way to locate the link. You will then either have to execute the JavaScript or, if you're sure the script won't change often, replicate the code in Java to come up with the same URL.

Then, you can use HttpClient again to download the document directly.

If you need to execute the JavaScript, you can use Rhino. If the script accesses various objects from the browser environment, look at envjs.

Community
  • 1
  • 1
Aaron Digulla
  • 297,790
  • 101
  • 558
  • 777
  • Thanks. +1 . Actually I was hoping NOT to use Selenium at all . I am establishing HttpUrlConnection . Is there any way to stream that file directly – Andrei Vasilev Mar 28 '14 at 14:36
  • 1
    @Andrei Vasilev - yes, that is the recommended way, using Apache HTTPClient, as Aaron suggests above. – djangofan Mar 28 '14 at 16:31