[英]Not able to click on popup allert message“OK or Cancel” with PhantomJS Selenium Java, working fine with IE
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.
我们在JAVA中嵌入java脚本并使用phantomJS进行操作。
Not sure how to handle with javascript two popup consequently and embed it with java and get it work with phantomJS. 不知道如何处理javascript两个popup因此并将其嵌入java并使其与phantomJS一起使用。
With IE we are able to handle pop with switch alert and working fine.. 使用IE,我们能够处理pop与切换警报和工作正常..
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. 还尝试使用此代码获取页面标题并使用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();"
+ "})");
You've got a typo, unterminated string: 你有一个错字,未终止的字符串:
engine.eval("var webPage = require('webpage');
^
+ "var page = webPage.create();"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.