Interaction with a PDF popup in Selenium

I am trying to check a page where clicking a button creates a popup that is in PDF format. I would like selenium to click on the popup and take a screenshot or save the PDF.

I use the following code to get all window handles for using the switchTo() command, but when I switchTo() it, it returns only one window. Selenium doesn't seem to recognize the pdf popup.

 Set<String> handles = driver.getWindowHandles(); //converts set to array String[] array = handles.toArray(new String[0]); System.out.println(Arrays.asList(array)); 

Is there any other way to switch to pdf popup?

+4
source share
1 answer

Since Selenium can control only those objects that the DOM can control (only JavaScript works in the IDE), you cannot take a screenshot. Your only option is to save it if the JavaScript for the new HTML5 is not powerful enough to run things on the operating system (I don't know). I will let you find the code to save the PDF file to Google using JavaScript, but this information should get you started. Just create a custom command called Selenium.prototype.doLaunchAndSavePDF or something else to run your PDF file and save it. And let your โ€œtargetโ€ parameter be the path and file name. I'm not sure how Selenium passes forward (or backward) slashes to JavaScript, so be careful. Good luck

Option No. 1 - when using the Selenium IDE:

Specify the user-extensions.js file in the Selenium IDE section> Parameters (menu)> Parameters (menu item)> General tab, then go to the file in the Selenium Kernel Extensions section.

Option number 2 - when using Selenium RC Server:

If you are not using an IDE and are using a Selenium RC server with a client driver (for example, JUnit), you must specify the * .js file path with the -userExtensions parameter when starting Selenium RC Server at the command line. But you said you just want to use an IDE, so I will ignore this. To use the Selenium RC server, a completely different configuration is required.

java -jar selenium-server.jar -userExtensions user-extensions.js

=========================

I made the following user command (JavaScript function) in my user file user-extensions.js. I had to exit and restart the IDE before it detected it. Type everything after "do" in the "Command" field of the IDE to find the custom command. Looks like he also added "customAlertAndWait" to the IDE.

Code in user-extensions.js file:

Selenium.prototype.doCustomAlert = function (sTarget, sValue) {alert ('Target:' + sTarget + '... Value:' + sValue); };

Selenium IDE Team Details:

Command: customAlert
Goal: Custom Target
Value: custom warning value

+2
source

All Articles