【问题标题】:click() function is missing on DOM element in evaluate() in CasperJSCasperJS中评估()中的DOM元素缺少click()函数
【发布时间】:2015-11-15 06:55:36
【问题描述】:

与 CasperJS 相比,我在 Chrome 控制台中的 DOM 元素上看到了不同的方法。我有以下运行

var casper = require('casper').create({
  verbose: true,
  logLevel: "debug"
});

var url = 'http://casperjs.org/';

casper.start(url, function() {
  this.echo('sdfsdf');
});

casper.then(function() {
  var link = this.evaluate(function() {
    var b = document.querySelector(".page-header");
    var s = "";

    for (var m in b) {
      if (typeof b[m] === 'function') {
        s += JSON.stringify(m) + " ";
      }
    }
    return s;
  });
  console.log(link);
});

casper.run();

它产生

"children" "childNodes" "insertAdjacentElement" "insertAdjacentHTML" "insertAdjacentText" "setAttribute" "getElementsByTagName" “getAttribute” “querySelectorAll” “webkitMatchesSelector” “getElementsByClassName” “包含” “getBoundingClientRect” “removeAttribute” “querySelector” “hasAttribute” “getAttributeNode” “getAttributeNS” “getElementsByTagNameNS” “removeAttributeNS” “getClientRects” “scrollByPages” “setAttributeNode” “setAttributeNS” “hasAttributeNS” “模糊” “scrollIntoViewIfNeeded” “scrollByLines” "setAttributeNodeNS" "removeAttributeNode" "getAttributeNodeNS" “焦点” “scrollIntoView” “addEventListener” “appendChild” “cloneNode” "removeChild" "removeEventListener" "compareDocumentPosition" "insertBefore" "hasAttributes" "isSupported" "isEqualNode" “dispatchEvent” “isDefaultNamespace” “hasChildNodes” “规范化” "replaceChild" "isSameNode" "lookupPrefix" "lookupNamespaceURI"

另一方面,如果我在 Chrome 的控制台中运行以下代码

var b = document.querySelector(".page-header");
var s = "";
for (var m in b) {
  if (typeof b[m] === 'function') {
    s += JSON.stringify(m) + " ";
  }
}

我得到以下信息。为什么 CasperJS 缺少 click?

""点击""焦点""模糊""hasAttributes""getAttribute" “getAttributeNS” “setAttribute” “setAttributeNS” “removeAttribute” “removeAttributeNS” “hasAttribute” “hasAttributeNS” “getAttributeNode” “getAttributeNodeNS” “setAttributeNode” “setAttributeNodeNS” “removeAttributeNode”“最接近”“匹配”“getElementsByTagName” "getElementsByTagNameNS" "getElementsByClassName" "insertAdjacentHTML" "createShadowRoot" "getDestinationInsertionPoints" "requestPointerLock" "getClientRects" "getBoundingClientRect" "scrollIntoView" "insertAdjacentElement" "insertAdjacentText" “scrollIntoViewIfNeeded” “webkitMatchesSelector” “动画” “删除” “webkitRequestFullScreen” “webkitRequestFullscreen” “querySelector” “querySelectorAll”“hasChildNodes”“规范化”“cloneNode” "isEqualNode" "compareDocumentPosition" "包含" "lookupPrefix" "lookupNamespaceURI" "isDefaultNamespace" "insertBefore" "appendChild" “replaceChild” “removeChild” “isSameNode” “addEventListener” "removeEventListener" "dispatchEvent" "

【问题讨论】:

    标签: javascript click phantomjs casperjs


    【解决方案1】:

    如果您使用的是 PhantomJS 1.x,则支持 click(),但仅限于 <input> 和 <button> 元素。请参阅MDN 了解更多信息。请注意,PhantomJS 1.x 与 Chrome 13 相当,并且在 Chrome 20 中引入了对 click() 的全面支持。

    此支持已扩展到 PhantomJS 2 中的所有元素类型,因为它在底层有一个 newer Webkit version。


    要么使用 CasperJS'click():

    casper.click(selector);
    

    或 PhantomJS 的众多解决方法之一:PhantomJS; click an element

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多