Closed Bug 749862 Opened 12 years ago Closed 12 years ago

findElements with css selector only returns a single element

Categories

(Remote Protocol :: Marionette, defect)

15 Branch
x86
macOS
defect
Not set
major

Tracking

(Not tracked)

RESOLVED FIXED
mozilla15

People

(Reporter: jlal, Assigned: mdas)

Details

Attachments

(2 files, 1 obsolete file)

Attached file Target html fragment
While testing the marionette js driver I found that findElements fails to return all of the elements that match the selector.

in the python driver I see a similar result except it causes an error inside
the python script.

//start session
marionette.find_elements('css selector', 'div');
// one element returns
marionette.find_elements('tag name', 'div');
//42 elements
marionette.execute_script('return document.querySelectorAll(\'div\').length; ');
//42 elements

Attached is the contents of the body element on the page I was testing this command on. This is actually the system app in b2g.
Attached patch Fix v0.1 (obsolete) — Splinter Review
querySelectorAll returns a NodeList, and not a list of elements, so this was just a quick fix.

I found a similar problem with find_elements("name",...), so I fixed that in this patch.

I updated the tests to try a basic find_elements() call for each supported search type.
Attachment #621714 - Flags: review?(jgriffin)
Comment on attachment 621714 [details] [diff] [review]
Fix v0.1

Review of attachment 621714 [details] [diff] [review]:
-----------------------------------------------------------------

::: testing/marionette/marionette-elements.js
@@ +402,5 @@
>          elements = this.findByXPathAll(rootNode, value, startNode);
>          break;
>        case NAME:
> +        elements = startNode.getElementsByName ?
> +                  startNode.getElementsByName(value) : 

reindent

@@ +429,5 @@
>        case SELECTOR:
> +        let matches = rootNode.querySelectorAll(value);
> +        for (let i = 0; i <  matches.length; i++) {
> +          elements.push(matches[i]);
> +        }

elements = Array.prototype.slice.call(matches);

tends to be how people do this
Attached patch Fix v0.2Splinter Review
Thanks, I've updated the patch
Attachment #621714 - Attachment is obsolete: true
Attachment #621714 - Flags: review?(jgriffin)
Attachment #621727 - Flags: review?(jgriffin)
Comment on attachment 621727 [details] [diff] [review]
Fix v0.2

Thanks!
Attachment #621727 - Flags: review?(jgriffin) → review+
http://hg.mozilla.org/integration/mozilla-inbound/rev/6d4fbeb32fbf
Assignee: nobody → mdas
Target Milestone: --- → mozilla15
https://hg.mozilla.org/mozilla-central/rev/6d4fbeb32fbf
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: