Below is the code that we are trying to click the first popup message after clicking on another popup also triggers and need to click that also. We are embedding java-script in JAVA and doing it with phantomJS.
Not sure how to handle with javascript two popup consequently and embed it with java and get it work with phantomJS.
With IE we are able to handle pop with switch alert and working fine..
ScriptEngineManager factory =new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
File file = new File("C:/esi-sofea/phantom/phantom/phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
PhantomJSDriver driver = new PhantomJSDriver();
engine.eval("var webPage = require('webpage');
+ "var page = webPage.create();"
+ "page.onConfirm = function(msg) {"
+ "console.log('CONFIRM: ' + msg);"
+ "return true; // `true` === pressing the "OK" button, `false` === pressing the "Cancel" button
+ "}");
Also tried this code to get page title and working fine with phantomJS.
ScriptEngine engine = factory.getEngineByName("JavaScript");
File file = new File("C:/esi-sofea/phantom/phantom /phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
PhantomJSDriver driver = new PhantomJSDriver();
engine.eval("var webPage = require('webpage');"
+ "var page = webPage.create();"
+ "page.open('http:www.google.com', function (status) {"
+ "console.log(page.title); "
+ "phantom.exit();"
+ "})");