microsoft / WinAppDriver

Windows Application Driver
MIT License
3.56k stars 1.39k forks source link

Pdf automation #1129

Open DeepikaVaishnave opened 4 years ago

DeepikaVaishnave commented 4 years ago

Hi, I have a scenerio in which upon clicking on a link in a desktop application PDF document get saved to the desired location. Is there any means by which i can launch the pdf from that location and verify PDF launched successfully.

FYI: i am not able to take control of the pdf document.

Thanks in advance.

anunay1 commented 4 years ago

No you cannot take controls for PDF using WAD, the better way to do this to use an OCR and do a text comparison to check whether PDF opened or not.

DeepikaVaishnave commented 4 years ago

Thanks for the response !

But if pdf is opening in the Microsoft Edge . Can we take control of that window and check whether PDF is opened in the tab?

anunay1 commented 4 years ago

This is a bit tricky, You need to use selenium to take control on the existing edge session & check the tab name to verify that the PDF is opened successfully. WAD will not be of any help.

trashbat commented 4 years ago

It depends on your definition of "launched successfully". If you want to verify that it rendered correctly, then no WAD won't help you.

But you could search for something like the following XPath from a root session, assuming the file is called foo.pdf:

//Window[@Name="Microsoft Edge"]/ListItem[starts-with(@Name, "foo.pdf")]

So then you'd know if an Edge window is open with a tab corresponding to the filename of the PDF. But if the filename isn't unique then there's no way of knowing it's the actual PDF file that you just generated, in which case you could use something like this:

//Window[@Name="Microsoft Edge"]//Pane[@Name="file://C:\\path\\to\\foo.pdf"]//Document

If the PDF contains text rather than just binary data then you could also use the text property of this element to do some string matching and check the contents of the PDF.

bibinroy commented 3 years ago

Hi is there any way to close the edge browser atleast

anunay1 commented 3 years ago

You can use send keys alt+f4 or else create a roorsession and with the top level window call driver.quit

bibinroy commented 3 years ago

Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_F4); robot.keyRelease(KeyEvent.VK_ALT); robot.keyRelease(KeyEvent.VK_F4);

I used the above method to close the edge browser, also tried action Event and send keys.. Both these method doesnt work

shilpamalhotra-git commented 2 years ago

Hey @anunay1 @bibinroy Were you able to find something around this. I am stuck in similar situation.

anunay1 commented 2 years ago

What all have you already tried?

shilpamalhotra-git commented 2 years ago

In my case, the pdf gets opened in Microsoft Edge. I actually do not need the control to Microsft Edge, need to just read/download the pdf (whatever works), so i just need the url. But The issue is that URL is dynamic - contains datetimestamp till milisec. So, I was trying to generate similar URL using my code so that I can direct download the PDF(using java code) but since it's till millisec, failed. Then I was looking into some wild card or regular exp to write the URL like "static URL + date + wildcard(*).pdf", this too not working, may be I don't know how wildcards actually work in URLs in such cases

anunay1 commented 2 years ago

@shilpamalhotra-git I can see in inspect that the download button is identified, just create a root session switch to the opened edge browser window and click on the download button

shilpamalhotra-git commented 2 years ago

@anunay1 Is there any alternative to this? Since it's tricky and complex in my framework to create root session.

anunay1 commented 2 years ago

Why is it complex to create a root session, that will be hardly 20 lines of code. And if adding 20 lines for code is complex then your framework is worthless.

anunay1 commented 2 years ago

if you need any more discussion please schedule a zoom call anunayathakur1@gmail.com at 6: 15 PM(IST).

shilpamalhotra-git commented 2 years ago

@anunay1 Could you please suggest java equivalent of - "var appTopLevelWindowHandleHex = appTopLevelWindowHandle.ToString("x"); //convert number to hex string". I was trying to switch to the desired app using root. But not able to achieve so with java. All the examples I could find are in C#.

anunay1 commented 2 years ago

check #1578