casper.visible('#percent_med_pickup');
返回true,而具有相同选择器的以下代码返回false:
casper.evaluate(function(){
return $('#percent_med_pickup').is(':visible');
});
不是都一样吗?
答案 0 :(得分:2)
是的,他们非常不同。
CasperJS(source):
this.elementVisible = function elementVisible(elem) {
var style;
try {
style = window.getComputedStyle(elem, null);
} catch (e) {
return false;
}
var hidden = style.visibility === 'hidden' || style.display === 'none';
if (hidden) {
return false;
}
if (style.display === "inline" || style.display === "inline-block") {
return true;
}
return elem.clientHeight > 0 && elem.clientWidth > 0;
};
jQuery(source):
jQuery.expr.filters.hidden = function( elem ) {
// Support: Opera <= 12.12
// Opera reports offsetWidths and offsetHeights less than zero on some elements
return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
};
jQuery.expr.filters.visible = function( elem ) {
return !jQuery.expr.filters.hidden( elem );
};