java - Handling Alert/Confirm with JavascriptExecutor in Selenium GhostDriver -
I am frustrated I am using Java in Prem Kija with Java 1.1.0 selenium 2.42.2. For my test, it is necessary that I identify and store alerts and confirmation messages and maybe when I open the page, the Pretium driver does not apply it yet, so I need to work with Javascript Extractor but I I am a js knob and can not manage it alone. Here's my code and what I tried:
desired capabilities dcaps = new desirable capabilities (); String [] phataeorgs = new string [] {"--webdriver-loglevel = NONE"}; Dcaps.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true); Dcaps.setCapability (CapabilityType.SUPPORTS_ALERTS, true); Dcaps.setCapability (PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath ()); Dcaps.setCapability (PhantomJSDriverService.PHANTOMJS_CLI_ARGS, FontArgS); Dcaps.setJavascriptEnabled (true); WebDriver driver = new fandommedsdrive (DCEP); Javascript explorer js = (javascript expander) driver; String script = "window.confirm = function (message) {" + document.lastConfirmationMessage = message; Return true;} "; js.executeScript (script); driver.get (" http://www.mysiteWithConfirm.de "); Object message = js.executeScript (" return document.lastConfirmationMessage "); < / Pre> When I open my site, it confirms immediately opening, so I know that there is a confirmation but I have got an exception
error message = & Gt; 'Variable can not be found: last confirmation confirmation'
I do not think The way you are trying to do it, that The way to solve.FontmaxDriver (GhostDrive) API currently does not support handling the alert ()
For this, it is possible to rewrite the possible solution window.Alert will therefore output the logs to the console. ALERT With labels, you can distinguish your alert message log from the other logs to the console.
page.evaluate (function () {window.alert = function (str) {console.log (" ALERT: "+ str);}}}; Page.onConsoleMessage (function (message, line number, source ID) {if (/ ^ ALERT: /. Exam (message)) {// do something with message}}); Based on my answer on this.
Comments
Post a Comment