How to automate a popup which having PDF

1,811 views
Skip to first unread message

ambrishkumarsoni

unread,
Aug 25, 2011, 1:53:46 AM8/25/11
to webd...@googlegroups.com
Hi,
i have a scenario where when you click on a link it will pop up a window having PDF file and i want validate the content whether it is over thr or not?


--
Thanks,
Ambrish Kumar | go green

Krishnan Mahadevan

unread,
Aug 25, 2011, 3:16:08 AM8/25/11
to webd...@googlegroups.com

Not sure if Selenium would be able to validate the contents of a PDF file opened. Here's how you can get this done using Java.

Your method would be this :

public String getTextFromPDF(URL url) throws IOException{
BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());
PDFParser parser = new PDFParser(fileToParse);
parser.parse();
String text = new PDFTextStripper().getText(parser.getPDDocument());
System.out.println(text);
parser.getPDDocument().close();
return text;
}

You would invoke the method as below:

URL url = new URL("http://illiad.evms.edu/sample.pdf");
System.out.println(getTextFromPDF(url));

Once you have the text you can use any asserts for getting your validation done.

If you are using Maven for your dependency management, you would add the below as a dependency

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.1.0</version>
</dependency>

Hope that helps !

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Cléuber José

unread,
Aug 25, 2011, 4:56:29 PM8/25/11
to webd...@googlegroups.com
Very good, Thanks!



2011/8/25 Krishnan Mahadevan <krishnan.ma...@gmail.com>



--
Att.
    Cléuber José

ambrishkumarsoni

unread,
Aug 29, 2011, 2:58:21 AM8/29/11
to webd...@googlegroups.com
Thanks Krishnan,

I done the same  but when i am executing my scenario its throwing  an exception as below :-

com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
java.net.URL.openStream(Unknown Source)
com.webdriver.browser.BasePage.getTextFromPDF(BasePage.java:262)
com.webDriverTestNG.EPacketTestPlan.ePacketSignINTest(EPacketTestPlan.java:52)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
org.testng.internal.Invoker.invokeMethod(Invoker.java:685)
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1200)
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
org.testng.TestRunner.privateRun(TestRunner.java:754)
org.testng.TestRunner.run(TestRunner.java:614)
org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
org.testng.SuiteRunner.run(SuiteRunner.java:241)
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
org.testng.TestNG.runSuitesSequentially(TestNG.java:1169)
org.testng.TestNG.runSuitesLocally(TestNG.java:1094)
org.testng.TestNG.run(TestNG.java:1006)
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:107)
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
sun.security.validator.PKIXValidator.doBuild(Unknown Source)
sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
sun.security.validator.Validator.validate(Unknown Source)
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source)
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
java.net.URL.openStream(Unknown Source)
com.webdriver.browser.BasePage.getTextFromPDF(BasePage.java:262)
com.webDriverTestNG.EPacketTestPlan.ePacketSignINTest(EPacketTestPlan.java:52)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
org.testng.internal.Invoker.invokeMethod(Invoker.java:685)
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1200)
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
org.testng.TestRunner.privateRun(TestRunner.java:754)
org.testng.TestRunner.run(TestRunner.java:614)
org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
org.testng.SuiteRunner.run(SuiteRunner.java:241)
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
org.testng.TestNG.runSuitesSequentially(TestNG.java:1169)
org.testng.TestNG.runSuitesLocally(TestNG.java:1094)
org.testng.TestNG.run(TestNG.java:1006)
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:107)
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
java.security.cert.CertPathBuilder.build(Unknown Source)
sun.security.validator.PKIXValidator.doBuild(Unknown Source)
sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
sun.security.validator.Validator.validate(Unknown Source)
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source)
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
java.net.URL.openStream(Unknown Source)
com.webdriver.browser.BasePage.getTextFromPDF(BasePage.java:262)
com.webDriverTestNG.EPacketTestPlan.ePacketSignINTest(EPacketTestPlan.java:52)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
org.testng.internal.Invoker.invokeMethod(Invoker.java:685)
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1200)
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
org.testng.TestRunner.privateRun(TestRunner.java:754)
org.testng.TestRunner.run(TestRunner.java:614)
org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
org.testng.SuiteRunner.run(SuiteRunner.java:241)
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
org.testng.TestNG.runSuitesSequentially(TestNG.java:1169)
org.testng.TestNG.runSuitesLocally(TestNG.java:1094)
org.testng.TestNG.run(TestNG.java:1006)
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:107)
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)

any suggestion guys?
Thanks,
Ambrish

Krishnan Mahadevan

unread,
Aug 29, 2011, 4:35:30 AM8/29/11
to webd...@googlegroups.com
Seems like you are trying to load a URL which is on a secure connection (your URL seems to be starting with https://)

Can your pdf be loaded merely by typing the full URL or does it require an authentication before the end user is shown the pdf in question.

If that is the case, then you would have to write up the code to ensure that the pdf that gets opened in the browser window, can be saved to the local desktop and then work with it.

If your pdf url (https://) doesnt require any authentication but is merely served from a https URL, then the following can help you get past your issue.

public static String getTextFromPDF(URL url) throws IOException{
HostnameVerifier hv = new HostnameVerifier() {
   @Override
   public boolean verify(String urlHostName, SSLSession session) {
return true;

   }
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
URLConnection connection = null;
SSLUtility.trustAllHttpsCertificates();
BufferedInputStream fileToParse = new BufferedInputStream(connection.getInputStream());
PDFParser parser = new PDFParser(fileToParse);
parser.parse();
String text = new PDFTextStripper().getText(parser.getPDDocument());
System.out.println(text);
parser.getPDDocument().close();
return text;
}


public class SSLUtility implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {

    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
        return null;
    }

    public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) {
        return true;
    }

    public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) {
        return true;
    }

    public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
            throws java.security.cert.CertificateException {
        return;
    }

    public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
            throws java.security.cert.CertificateException {
        return;
    }

    public static void trustAllHttpsCertificates() throws Exception {
        // Create a trust manager that does not validate certificate chains:
        javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
        javax.net.ssl.TrustManager tm = new SSLUtility();
        trustAllCerts[0] = tm;
        javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, null);
        javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    }

}




Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--

ambrishkumarsoni

unread,
Aug 29, 2011, 5:23:44 AM8/29/11
to webd...@googlegroups.com
Hi,

URLConnection connection = null;
BufferedInputStream fileToParse = new BufferedInputStream(connection.getInputStream());
SSLUtility.trustAllHttpsCertificates();

This is null so it is throwing null pointer exception.
Thanks,
Ambrish

Krishnan Mahadevan

unread,
Aug 29, 2011, 5:35:14 AM8/29/11
to webd...@googlegroups.com
Oops.
Forgot to include the following line

connection = new URL(URL).openConnection();
 after

URLConnection connection = null;


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--

ambrishkumarsoni

unread,
Aug 29, 2011, 8:40:02 AM8/29/11
to webd...@googlegroups.com
Hi Krishnan,
Actually i tried in all d way but that error still coming so i think i should go another way like by saving the pdf into local disk and then read the text.
Thanks for you quick responses.
Thanks,
Ambrish

Vitali Kasyanenka

unread,
Sep 29, 2011, 6:31:44 AM9/29/11
to webdriver
Krishnan, is it possible to get pdf without using the direct link to
it?
We have an application (GWT) which generates PDF files and show them
in a new GWT popup window.
This window contains a servlet which shows the PDF file. I can get an
url to this file and it looks like
http://siteadress/PdfManagerServlet?documentType=ProgressLetter&StudentId=881&BeginDate=1317081600000&EndDate=1317168000000.
But when i try to give this url to my test it returns 403 error after
the url.openStream(). Do you know what's wrong?

Krishnan Mahadevan

unread,
Sep 30, 2011, 12:23:40 AM9/30/11
to webd...@googlegroups.com
Vitali,

Error return code of 403 = Forbidden.

Not sure what exactly is going on there... 
The other option that I can think of is, couple Robot commands from within Selenium and have selenium save the file in question to your local machine and then read the file from your local file system.

Hope that helps..

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Vitali Kasyanenka

unread,
Oct 25, 2011, 4:58:41 AM10/25/11
to webd...@googlegroups.com
Krishnan,
thanks for your ideas but i've solved this issue in a different way.
Hope this will help anyone:

public String getTextFromPDF(URL url) throws IOException {
        Cookie authorizationCookie = getBrowser().manage().getCookieNamed("JSESSIONID") ;
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("Cookie", authorizationCookie.toString());
        InputStream fileToParse = conn.getInputStream();

Krishnan Mahadevan

unread,
Oct 25, 2011, 6:52:04 AM10/25/11
to webd...@googlegroups.com
Awesome !!
Never knew that we could couple a URLConnection to make use of the same session by relying on cookies :)


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/0MbLD_5lFokJ.

Jakes

unread,
Nov 8, 2011, 1:47:39 PM11/8/11
to webdriver
I am trying to download a PDF document for content validation Cookie
Authentication didn't work for me.
Can some one shed some light on Security Certificate authentication
java URL download?

On Oct 25, 2:52 am, Krishnan Mahadevan
<krishnan.mahadevan1...@gmail.com> wrote:
> Awesome !!
> Never knew that we could couple a URLConnection to make use of the same
> session by relying on cookies :)
>
> Thanks & Regards
> Krishnan Mahadevan
>
> "All the desirable things in life are either illegal, expensive, fattening
> or in love with someone else!"
>
> On Tue, Oct 25, 2011 at 2:28 PM, Vitali Kasyanenka <pnevmos...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Krishnan,
> > thanks for your ideas but i've solved this issue in a different way.
> > Hope this will help anyone:
>
> > *public String getTextFromPDF(URL url) throws IOException {
> > *
> > *        Cookie authorizationCookie =
> > getBrowser().manage().getCookieNamed("JSESSIONID") ;*
> > *        URLConnection conn = url.openConnection();*
> > *        conn.setRequestProperty("Cookie",
> > authorizationCookie.toString());*
> > *        InputStream fileToParse = conn.getInputStream();*
> > *        PDFParser parser = new PDFParser(fileToParse);*
> > *        parser.parse();*
> > *        String text = new
> > PDFTextStripper().getText(parser.getPDDocument());*
> > *        System.out.println(text);*
> > *        parser.getPDDocument().close();*
> > *        return text;*
> > *    }*

Usha M Gowda

unread,
May 16, 2012, 12:51:45 AM5/16/12
to webd...@googlegroups.com
Hi,

I have a scenario like need to validate the pdf contents but directly i cannot read the pdf.. if saved pdf, then i can read it so i need to save the pdf to local machine.
Can anyone help me how to save pdf file to local desktop.
To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

Krishnan Mahadevan

unread,
May 16, 2012, 5:48:20 AM5/16/12
to webd...@googlegroups.com
Have you tried the implementation that I provided in this thread ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/KcL_jUqaTqwJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

Usha M Gowda

unread,
May 16, 2012, 6:08:20 AM5/16/12
to webd...@googlegroups.com
i tried for the below code the content type is returning null so not
able to go further.


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

URL url1 =
//new URL("http://www.gnostice.com/downloads/Gnostice_PathQuest.pdf");
new URL("https://www.myhl.qa3.hrbl.net/Documents/DistributorApplication.aspx");

byte[] ba1 = new byte[1024];
int baLength;
FileOutputStream fos1 = new FileOutputStream("download.pdf");

try {
//Contacting the URL
System.out.print("Connecting to " + url1.toString() + " ... ");
URLConnection urlConn = url1.openConnection();

// Checking whether the URL contains a PDF
if (!urlConn.getContentType().equalsIgnoreCase("application/pdf")) {
System.out.println("FAILED.\n[Sorry. This is not a PDF.]");
} else {
try {

// Read the PDF from the URL and save to a local file
InputStream is1 = url1.openStream();
while ((baLength = is1.read(ba1)) != -1) {
fos1.write(ba1, 0, baLength);
}
fos1.flush();
fos1.close();
is1.close();

// Load the PDF document and display its page count
System.out.print("DONE.\nProcessing the PDF ... ");
PdfDocument doc = new PdfDocument();
try {
// doc.load("download.pdf");
System.out.println("DONE.\nNumber of pages in the PDF is " +
doc.getPageSize());
doc.close();
} catch (Exception e) {
System.out.println("FAILED.\n[" + e.getMessage() + "]");
}

} catch (ConnectException ce) {
System.out.println("FAILED.\n[" + ce.getMessage() + "]\n");
}
}

} catch (NullPointerException npe) {
System.out.println("FAILED.\n[" + npe.getMessage() + "]\n");
}*/
>>>> webdriver+...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/webdriver?hl=en.
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "webdriver" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/webdriver/-/KcL_jUqaTqwJ.
>>
>> To post to this group, send email to webd...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> webdriver+...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/webdriver?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to

Krishnan Mahadevan

unread,
May 16, 2012, 6:11:44 AM5/16/12
to webd...@googlegroups.com
Usha, 
You seem to be working with a "https" site.
When I load the url " https://www.myhl.qa3.hrbl.net/Documents/DistributorApplication.aspx " it gives me a Server not found. So am guessing its a intranet site.

Does this URL require authentication ?
If yes, then my provided method wouldnt work for you.

Also I see that you are referring to 
If you look closely in my example, I would set a connection to the actual pdf's URL itself.

So if its a link that you would need to extract from your DistributorApplication.aspx you would further need to apply some URL fetching logic in your code before you can consume it.

The code snippet I provided was more like a reference point to help you get started and not like a "Ready to consume" solution.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Manoj

unread,
May 18, 2012, 11:27:29 AM5/18/12
to webdriver
Hi everyone....if you all discussing on how to download/save Pdf in
local machine then i have a solution so let me know the exact problem.


Regards
Manoj

On May 16, 3:11 pm, Krishnan Mahadevan
<krishnan.mahadevan1...@gmail.com> wrote:
> Usha,
> You seem to be working with a "https" site.
> When I load the url "https://www.myhl.qa3.hrbl.net/Documents/DistributorApplication.aspx" it
> gives me a Server not found. So am guessing its a intranet site.
>
> Does this URL require authentication ?
> If yes, then my provided method wouldnt work for you.
>
> Also I see that you are referring to
>    new URL("https://www.myhl.qa3.hrbl.net/Documents/DistributorApplication.aspx");
>
> If you look closely in my example, I would set a connection to the actual
> pdf's URL itself.
>
> So if its a link that you would need to extract from your
> DistributorApplication.aspx you would further need to apply some URL
> fetching logic in your code before you can consume it.
>
> The code snippet I provided was more like a reference point to help you get
> started and not like a "Ready to consume" solution.
>
> Thanks & Regards
> Krishnan Mahadevan
>
> "All the desirable things in life are either illegal, expensive, fattening
> or in love with someone else!"
>
> > > On Wed, May 16, 2012 at 10:21 AM, Usha M Gowda <usha.gowd...@gmail.com>

Mark Collin

unread,
May 18, 2012, 11:59:49 AM5/18/12
to webd...@googlegroups.com
Why don't you just post your solution...

Manoj

unread,
May 19, 2012, 9:24:58 AM5/19/12
to webdriver
Mark@..ohok....

driver.get(baseUrl);
String Win=driver.getWindowHandle();
System.out.println(Win);
driver.findElement(By.xpath("(//input[@name='button']")).click();
(Click pdf link)
Set<String> Win2=driver.getWindowHandles();
System.out.println(ww.size());
String PDF=null;
int i=2;
for(String P: Win2){
if(!Win2.equals(Win)){
PDF=P;
driver.switchTo().window(PDF);
driver.manage().window().maximize();
driver.switchTo().defaultContent();
Robot r=new Robot();
r.keyPress(KeyEvent.VK_ALT);
r.keyRelease(KeyEvent.VK_ALT);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
}
}}

On May 18, 8:59 pm, "Mark Collin" <mark.col...@lazeryattack.com>
wrote:

Sumit Saxena

unread,
Jul 3, 2012, 8:59:36 AM7/3/12
to webd...@googlegroups.com
Hi Manoj

I have tried above code but not got any success


                        I have to save file in local machine.
Thanks
Sumit

On Tue, Jul 3, 2012 at 5:48 PM, Sumit Saxena <sumit...@gmail.com> wrote:


---------- Forwarded message ----------
From: Sumit Saxena <sumit...@gmail.com>
Date: Tue, Jul 3, 2012 at 5:47 PM
Subject: Fwd: [webdriver] Re: How to automate a popup which having PDF
To: "shilpi.gupta2" <shilpi...@wipro.com>

Manoj

unread,
Jul 6, 2012, 12:08:52 AM7/6/12
to webd...@googlegroups.com
Hi Sumit

let me clear you...this code is for saving PDF in local machine.
now tell me which kind of success you did'nt get??

Regards
Manoj

> > > >>>> For more options, visit this group at
> > > >>>>http://groups.google.com/group/webdriver?hl=en.
>
> > > >> --
> > > >> You received this message because you are subscribed to the
> > > >> Google
> > > Groups
> > > >> "webdriver" group.
> > > >> To view this discussion on the web visit
> > > >>https://groups.google.com/d/msg/webdriver/-/KcL_jUqaTqwJ.
>
> > > >> To post to this group, send email to webd...@googlegroups.com.
> > > >> To unsubscribe from this group, send email to

> > > >> For more options, visit this group at
> > > >>http://groups.google.com/group/webdriver?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "webdriver" group.
> > > > To post to this group, send email to webd...@googlegroups.com.
> > > > To unsubscribe from this group, send email to

> > > > For more options, visit this group at
> > > >http://groups.google.com/group/webdriver?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "webdriver" group.
> > > To post to this group, send email to webd...@googlegroups.com.
> > > To unsubscribe from this group, send email to

> > > For more options, visit this group at
> > >http://groups.google.com/group/webdriver?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to
> For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

Sharon Francis

unread,
Jul 14, 2014, 2:15:00 AM7/14/14
to webd...@googlegroups.com

Hi,
         I am using the following code to download a pdf file . but its not downloading. Pls help

        public class BookDownload {


    public static void main(String[] args)
    {
        FirefoxProfile profile=new FirefoxProfile();
        profile.setPreference("browser.download.folderList",0);
        profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/pdf");
        WebDriver driver=new FirefoxDriver(profile);
        driver.get("http://it-ebooks.info/book/3123/");
         WebDriverWait wait=new WebDriverWait(driver,20);
         wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Instant Selenium Testing Tools Starter")));
        driver.findElement(By.linkText("Instant Selenium Testing Tools Starter")).click();
      
    }

}

Nagaraja ben

unread,
Jul 18, 2014, 5:40:30 AM7/18/14
to webd...@googlegroups.com
After   driver.findElement(By.linkText("Instant Selenium Testing Tools Starter")).click();
  add below code it ll work 
Robot robo=new Robot();
robo.keyPress(KeyEvent.VK_ENTER);
let me know  if its not working


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.

To post to this group, send email to webd...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages