Interacting with a PDF popup in Selenium

前端 未结 1 1847
悲哀的现实
悲哀的现实 2021-01-20 00:02

I\'m trying to test a page where clicking a button generates a popup that\'s in PDF form. I\'d like selenium to click on the popup and either take a screenshot of the screen

1条回答
  •  生来不讨喜
    2021-01-20 00:38

    Because Selenium can only control things that the DOM can control (the IDE is just running JavaScript) you cannot take a screen shot. Your only option is to save it, unless JavaScript for the new HTML5 is that powerful to launch things on the Operating System (I don't know). I will let you find the code to save a PDF on Google using JavaScript, but this information should get you started. Just create a custom command, called Selenium.prototype.doLaunchAndSavePDF or something, to launch your PDF and save it. And have your "target" parameter be the path and name of the file. I'm not sure how Selenium passes the forward (or backward) slashes to JavaScript, so be careful of that. Good luck!

    Option #1 - if using Selenium IDE:

    Specify the user-extensions.js file under Selenium IDE > Options (menu) > Options (menu option) > General Tab, then browse to your file under "Selenium Core Extensions".

    Option #2 - if using Selenium RC Server:

    If you're not using the IDE and using Selenium RC server with a client driver (like JUnit for example), you must specify the path of the *.js file with the -userExtensions parameter when you start the Selenium RC Server on the command line. But you said you just wanted to use the IDE, so I'd ignore this. It takes quite a bit of other setup to use the Selenium RC server.

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

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

    I made the following custom command (JavaScript function) in my custom user-extensions.js file.. I had to exit and restart the IDE before it found it. Type everything after the "do" in the "Command" field in the IDE to find the custom command. It looks like it also added a "customAlertAndWait" to the IDE as well.

    Code in user-extensions.js file:

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

    Selenium IDE command details:

    Command: customAlert
    Target: custom alert target
    Value: custom alert value

    0 讨论(0)
提交回复
热议问题