1

下面是我们在单击另一个弹出窗口后尝试单击第一个弹出消息的代码,也触发并且也需要单击它。我们在 JAVA 中嵌入 java-script 并使用 phantomJS 来完成。

因此不确定如何使用javascript处理两个弹出窗口并将其嵌入java并使其与phantomJS一起使用。

使用 IE,我们能够处理带有开关警报的弹出并且工作正常..

          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
           + "}");

还尝试了此代码来获取页面标题并与 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();"
                    + "})");
4

1 回答 1

0

你有一个错字,未终止的字符串:

engine.eval("var webPage = require('webpage');
                                              ^
        + "var page = webPage.create();"
于 2016-11-21T07:33:14.713 回答