简体   繁体   English

用PhantomJS Selenium Java无法点击popup allert消息“OK或Cancel”,与IE一起正常工作

[英]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.

相关问题 如何在Selenium IDE中的JS弹出窗口(身份验证)上单击“确定”或“取消” - How to Click 'OK' or 'CANCEL' on a JS popup (authentication) within Selenium IDE Selenium 测试 - 确定/取消弹出窗口立即消失 - Selenium test - OK/Cancel popup disappearing immediately VBS-IE-在JavaScript弹出窗口上单击“确定”的脚本 - VBS - IE - Script to click “OK” on a javascript popup 无法使用Java在Selenium Webdriver中单击弹出按钮 - Unable to click on a popup button in selenium webdriver with java IE 6 7无法在其他浏览器正常工作的情况下不显示弹出窗口的问题 - Problem with IE 6 7 not displaying popup where its working fine in other brwsrs 在 java 中处理 IE 的 selenium/nide 中的右键单击 - handle right click in selenium/nide for IE in java PhantomJS .click()不起作用 - PhantomJS .click() not working 双击取消日期选择在IE 10中不起作用 - Double click to cancel the date selection is not working in IE 10 点击事件在Chrome和FireFox中无法正常运行,但在IE浏览器中可以正常运行 - On Click Event is not working in Chrome and FireFox, but works fine in the IE browers 单击事件在 IE 中不起作用,但在其他浏览器中工作正常 - Click event is not working in IE but works fine in other browsers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM