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 .

3
  • The accepted answer to this SO post should get you started (in a nutshell: use java.net.HttpUrlConnection). Commented Mar 28, 2014 at 14:31
  • possible duplicate of Handling a popup window using selenium Commented Mar 28, 2014 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 \ Commented Mar 28, 2014 at 14:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 - yes, that is the recommended way, using Apache HTTPClient, as Aaron suggests above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.