Phantomjs-onalert

提供:Dev Guides
移動先:案内検索

PhantomJS-onAlert()

このコールバックは、ページにアラートがあるときに呼び出されます。 コールバックは文字列を受け取り、何も返しません。

構文

その構文は次のとおりです-

var wpage = require('webpage').create();
wpage.onAlert = function(msg) {};

次の例は、* onAlert()*メソッドの使用を示しています。

var wpage = require('webpage').create();
wpage.onAlert = function(str) {
   console.log(str);
}
wpage.open('http://localhost/tasks/alertl', function(status) {
  //wpage.stop();
   console.log(status);

   phantom.exit();
});

Alertl

<html>
   <head></head>
   <body>
      <script type = "text/javascript">
         alert("Welcome to phantomjs");
      </script>
      <h1>This is a test page</h1>
   </body>
</html>

上記のプログラムは、次の output を生成します。

Welcome to phantomjs
Success