findElements does not scope to parent

RESOLVED FIXED in Firefox 18

Status

Testing
Marionette
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: lightsofapollo, Assigned: fredy)

Tracking

Trunk
mozilla19
x86
Mac OS X
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox18 fixed, firefox19 fixed)

Details

Attachments

(1 attachment, 2 obsolete attachments)

(Reporter)

Description

5 years ago
STR:

marionette.navigate('https://developer.mozilla.org/en-US/docs/Mozilla/Boot_to_Gecko/Marionette_for_Interactive_Python')

head = marionette.find_element('css selector', '#article-head')
head.find_elements('css selector', 'div')

expected:

find elements to return the single 'div' element inside #article-head

actual:

all div elements in the entire document are returned.

--

My best guess is this related to: https://mxr.mozilla.org/mozilla-central/source/testing/marionette/marionette-elements.js#251

My build is from October 2nd (which is far after this code has been modified).
(Reporter)

Comment 1

5 years ago
the workaround is to do something like

marionette.find_elements('css selector', '#article-head div');
Created attachment 669143 [details] [diff] [review]
bugfix

At findElements function, on css-selector case, searching for the elements always starts at the rootNode which is the document and not at the current node (startNode).

The attached patch corrects this behavior.
Attachment #669143 - Flags: review?
Comment on attachment 669143 [details] [diff] [review]
bugfix

Can you add a test case for this too?
Attachment #669143 - Flags: review? → review?(dburns)
Created attachment 672024 [details] [diff] [review]
fix and unit test
Attachment #669143 - Attachment is obsolete: true
Attachment #672024 - Flags: review?(dburns)
Attachment #669143 - Flags: review?(dburns)
Comment on attachment 672024 [details] [diff] [review]
fix and unit test


> 
>+    def test_selector_scope(self):

Can we make the test name more verbose so we can, at a glance, work out what it is supposed to do. E.g. test_css_selector_scope_doesnt_start_at_rootnode

>+        el = self.marionette.execute_script("return window.document.getElementById('mozLink');")
>+        nav_el = self.marionette.execute_script("return window.document.getElementById('testDiv');")

Why are you using execute script instead of find_element here?
(In reply to David Burns :automatedtester from comment #5)
> Comment on attachment 672024 [details] [diff] [review]
> fix and unit test
> 
> 
> > 
> >+    def test_selector_scope(self):
> 
> Can we make the test name more verbose so we can, at a glance, work out what
> it is supposed to do. E.g. test_css_selector_scope_doesnt_start_at_rootnode
> 
Yes, that's sound better. I am going to fix that. 

> >+        el = self.marionette.execute_script("return window.document.getElementById('mozLink');")
> >+        nav_el = self.marionette.execute_script("return window.document.getElementById('testDiv');")
> 
> Why are you using execute script instead of find_element here?

I just saw it on some other tests in the same file, e.g. test_xpath.
I thought also that, just in case, the find_element function don't work, using execute script will make this test pass.
I can also fix this behavior.
(In reply to Alfredos-Panagiotis Damkalis (irc: fredy) from comment #6)
> Yes, that's sound better. I am going to fix that. 
> 
*that sounds better
Created attachment 672541 [details] [diff] [review]
patch v2

Name of the test is fixed and the execute_scripts replaced with find_element.
Attachment #672024 - Attachment is obsolete: true
Attachment #672024 - Flags: review?(dburns)
Attachment #672541 - Flags: review?(dburns)
Comment on attachment 672541 [details] [diff] [review]
patch v2

awesome work!
Attachment #672541 - Flags: review?(dburns) → review+
landed in m-i https://hg.mozilla.org/integration/mozilla-inbound/rev/f5760fcd8420
https://hg.mozilla.org/mozilla-central/rev/f5760fcd8420
Assignee: nobody → fredy
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Whiteboard: [automation-needed-in-aurora]
https://hg.mozilla.org/projects/ash/rev/059cdea17d24
https://hg.mozilla.org/releases/mozilla-aurora/rev/4ac2d634671d
status-firefox18: --- → fixed
status-firefox19: --- → fixed
Whiteboard: [automation-needed-in-aurora]
You need to log in before you can comment on or make changes to this bug.