assaf/zombie — Issue #182: Weird querySelector context behavior
Author: demian85
Created: 2011-10-08 17:30:12+00:00
State: open

This is driving me nuts, it works "sometimes". I'll try to give a basic example with this html fragment:

A

1

2

3

4

B

1

2

And this JS:

var parents = browser.css('#categTree > h3');
var children = browser.css('#categTree > ul');
children.forEach(function(c) {
console.log(c.getElementsByTagName('a').length);
});
children.forEach(function(c) {
console.log(c.querySelectorAll('a').length);
});

Output:

4
2
6
6

Why the context node is ignored? I use querySelector with explicit context node in other parts of my code and works just fine, I don't get it.

Btw, browser.css() returns an Array and browser.querySelector() returns a NodeList. Documentation says that both return a NodeList, how's that?