简体   繁体   English

CasperJS中valuate()中的DOM元素上缺少click()函数

[英]click() function is missing on DOM element in evaluate() in CasperJS

I am seeing different methods on a DOM element in Chrome's console compared to CasperJS. 与CasperJS相比,我在Chrome控制台中的DOM元素上看到了不同的方法。 I have the following that I run 我有以下跑步项目

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();

It produces 它产生

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

On other hand if I run the following code in Chrome's console 另一方面,如果我在Chrome的控制台中运行以下代码

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

I get the following. 我得到以下。 Why is the CasperJS missing click ? 为什么CasperJS缺少喀click

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

If you're using PhantomJS 1.x, then there is support for click() , but only on <input> and <button> elements. 如果您使用的是PhantomJS 1.x,则支持click() ,但仅支持<input><button>元素。 See MDN for more information. 有关更多信息,请参见MDN Note that PhantomJS 1.x is comparable to Chrome 13 and full support for click() was introduced in Chrome 20. 请注意,PhantomJS 1.x与Chrome 13相当,并且Chrome 20中引入了对click()完全支持。

This support was extended to all element types in PhantomJS 2, because it has a newer Webkit version under the hood. 该支持已扩展到PhantomJS 2中的所有元素类型,因为它具有更高级的Webkit版本


Either use CasperJS' click() : 使用CasperJS的click()

casper.click(selector);

or one of the many workarounds for PhantomJS: PhantomJS; 或用于PhantomJS许多解决方法之一: PhantomJS; click an element 点击一个元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM