{"id":857,"date":"2017-01-23T15:39:11","date_gmt":"2017-01-23T06:39:11","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=857"},"modified":"2017-01-26T11:09:49","modified_gmt":"2017-01-26T02:09:49","slug":"javascript-phantomjs%e3%81%a7%e3%82%b3%e3%83%b3%e3%83%86%e3%83%b3%e3%83%84%e3%81%8c%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%82%8b%e3%81%be%e3%81%a7%e5%be%85%e3%81%a4","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/javascript-phantomjs%e3%81%a7%e3%82%b3%e3%83%b3%e3%83%86%e3%83%b3%e3%83%84%e3%81%8c%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%82%8b%e3%81%be%e3%81%a7%e5%be%85%e3%81%a4\/","title":{"rendered":"[javascript] phantomjs\u3067\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u8868\u793a\u3055\u308c\u308b\u307e\u3067\u5f85\u3064"},"content":{"rendered":"<h2>phantomjs\u3067\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u8868\u793a\u3055\u308c\u308b\u307e\u3067\u5f85\u3064<\/h2>\n<p>phantomjs\u306f\u30d6\u30e9\u30a6\u30b6\u30ec\u30b9\u3067Javascript\u3092\u5b9f\u884c\u3067\u304d\u308b\u306e\u3067\u4fbf\u5229\u3060\u304c\u3001\u5168\u90e8\u306eJavascript\u304c\u51e6\u7406\u7d42\u4e86\u3059\u308b\u307e\u3067\u306f\u5f85\u3063\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u3001\u3042\u308b\u30b3\u30fc\u30c9\u304c\u8868\u793a\u3055\u308c\u308b\u307e\u3067\u5f85\u305f\u305b\u308b<\/p>\n<p>\uff12\uff15\uff10ms\u3054\u3068\u306b\u30da\u30fc\u30b8\u72b6\u614b\u3092\u78ba\u8a8d\u3057\u3001\u6700\u5927\uff13\u79d2\u5f85\u3064\u3002<br \/>\n#thediv\u304cvisible\u3060\u3063\u305f\u3089\u300cThe sign-in dialog should be visible now.\u300d\u3068\u8868\u793a\u3055\u305b\u3001\u51e6\u7406\u3092\u7d42\u4e86\u3055\u305b\u308b<\/p>\n<pre>\r\n\"use strict\";\r\nfunction waitFor(testFx, onReady, timeOutMillis) {\r\n    var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, \/\/< Default Max Timout is 3s\r\n        start = new Date().getTime(),\r\n        condition = false,\r\n        interval = setInterval(function() {\r\n            if ( (new Date().getTime() - start < maxtimeOutMillis) &#038;&#038; !condition ) {\r\n                \/\/ If not time-out yet and condition not yet fulfilled\r\n                condition = (typeof(testFx) === \"string\" ? eval(testFx) : testFx()); \/\/< defensive code\r\n            } else {\r\n                if(!condition) {\r\n                    \/\/ If condition still not fulfilled (timeout but condition is 'false')\r\n                    console.log(\"'waitFor()' timeout\");\r\n                    phantom.exit(1);\r\n                } else {\r\n                    \/\/ Condition fulfilled (timeout and\/or condition is 'true')\r\n                    console.log(\"'waitFor()' finished in \" + (new Date().getTime() - start) + \"ms.\");\r\n                    typeof(onReady) === \"string\" ? eval(onReady) : onReady(); \/\/< Do what it's supposed to do once the condition is fulfilled\r\n                    clearInterval(interval); \/\/< Stop this interval\r\n                }\r\n            }\r\n        }, 250); \/\/< repeat check every 250ms\r\n};\r\n\r\n\r\nvar page = require('webpage').create();\r\npage.open(\"http:\/\/xxxx.com\/test.php\", function (status) {\r\n    if (status !== \"success\") {\r\n        console.log(\"Unable to access network\");\r\n    } else {\r\n        console.log(\"Start Wait\");\r\n        waitFor(function() {\r\n            return page.evaluate(function() {\r\n                return $('#thediv').is(':visible');\r\n            });\r\n        }, function() {\r\n           console.log(\"visible now.\");\r\n           phantom.exit();\r\n        });\r\n    }\r\n});\r\n<\/pre>\n<p>\u5fdc\u7528\uff1a<br \/>\n\u3082\u3057<\/p>\n<h2>\u30bf\u30b0\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u3001\u6b21\u306e\u51e6\u7406\u306b\u79fb\u308a\u305f\u3044\u5834\u5408\u306f<\/p>\n<pre>\r\nwaitFor(function() {\r\n            return page.evaluate(function() {\r\n                return $('#thediv').is(':visible');\r\n            });\r\n        }, function() {\r\n           console.log(\"visible now.\");\r\n           phantom.exit();\r\n        });\r\n<\/pre>\n<p>\u3092<\/p>\n<pre>\r\nwaitFor(function() {\r\n            return page.evaluate(function() {\r\n                return document.getElementsByTagName('h2')[0].innerHTML != null;\r\n            });\r\n        }, function() {\r\n           console.log(\"visible now.\");\r\n           phantom.exit();\r\n        });\r\n<\/pre>\n<p>\u306b\u5909\u3048\u308b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>phantomjs\u3067\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u8868\u793a\u3055\u308c<\/p>\n","protected":false},"author":1,"featured_media":813,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[100],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/857"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=857"}],"version-history":[{"count":3,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/857\/revisions"}],"predecessor-version":[{"id":874,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/857\/revisions\/874"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/813"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}