Bug 1204496: When searching by link text start from the startNode and not the rootNode; r=ato
authorDavid Burns <dburns@mozilla.com>
Thu, 17 Sep 2015 22:22:38 +0100
changeset 295763 85b3e7100079de30cf23737c9ed2a1be6da13b12
parent 295762 60adc85f21cbeecdc3c326c60d06ef5938394d06
child 295764 80f0d809263aa58e3eec17326135f1db2aa891ac
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1204496
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1204496: When searching by link text start from the startNode and not the rootNode; r=ato
testing/marionette/client/marionette/tests/unit/test_findelement.py
testing/marionette/client/marionette/www/nestedElements.html
testing/marionette/elements.js
--- a/testing/marionette/client/marionette/tests/unit/test_findelement.py
+++ b/testing/marionette/client/marionette/tests/unit/test_findelement.py
@@ -164,8 +164,16 @@ class TestElements(MarionetteTestCase):
         import re
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         el = self.marionette.find_element(By.TAG_NAME, "body")
         uuid_regex = re.compile('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$')
         self.assertIsNotNone(re.search(uuid_regex, el.id),
                              'UUID for the WebElement is not valid. ID is {}'\
                              .format(el.id))
+    def test_should_find_elements_by_link_text(self):
+        test_html = self.marionette.absolute_url("nestedElements.html")
+        self.marionette.navigate(test_html)
+        element = self.marionette.find_element(By.NAME, "div1")
+        children = element.find_elements(By.LINK_TEXT, "hello world")
+        self.assertEqual(len(children), 2)
+        self.assertEqual("link1", children[0].get_attribute("name"))
+        self.assertEqual("link2", children[1].get_attribute("name"))
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/nestedElements.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<a href="1.html">hello world</a>
+<a href="1.html">hello world</a><a href="1.html">hello world</a>
+<div name="div1">
+  <a href="2.html" name="link1">hello world</a>
+  <a href="2.html" name="link2">hello world</a>
+</div>
+
+<a href="1.html">hello world</a><a href="1.html">hello world</a><a href="1.html">hello world</a>
--- a/testing/marionette/elements.js
+++ b/testing/marionette/elements.js
@@ -676,17 +676,17 @@ ElementManager.prototype = {
       case CLASS_NAME:
         elements = startNode.getElementsByClassName(value);
         break;
       case TAG:
         elements = startNode.getElementsByTagName(value);
         break;
       case LINK_TEXT:
       case PARTIAL_LINK_TEXT:
-        let allLinks = rootNode.getElementsByTagName('A');
+        let allLinks = startNode.getElementsByTagName('A');
         for (let i = 0; i < allLinks.length; i++) {
           let text = allLinks[i].text;
           if (PARTIAL_LINK_TEXT == using) {
             if (text.indexOf(value) != -1) {
               elements.push(allLinks[i]);
             }
           } else if (text == value) {
             elements.push(allLinks[i]);