Title: [225388] trunk/Source/WebKit
Revision
225388
Author
[email protected]
Date
2017-12-01 01:50:52 -0800 (Fri, 01 Dec 2017)

Log Message

WebDriver: link and partial links queries don't work in xhtml documents
https://bugs.webkit.org/show_bug.cgi?id=180191

Reviewed by Brian Burg.

We convert the queries to use xpath, which works for html documents, but it doesn't work for xhtml. In case of
xhtml we would need to provide a namespace resolver and elements would need to be prefixed with 'xhtml:'. It's
easier to simply iterate the link elements and compare the text.

Fixes: imported/w3c/webdriver/tests/retrieval/find_element_from_element.py::test_xhtml_namespace[link text-full link text]
       imported/w3c/webdriver/tests/retrieval/find_element_from_element.py::test_xhtml_namespace[partial link text-link text]
       imported/w3c/webdriver/tests/retrieval/find_element_from_elements.py::test_xhtml_namespace[link text-full link text]
       imported/w3c/webdriver/tests/retrieval/find_element_from_elements.py::test_xhtml_namespace[partial link text-link text]
       imported/w3c/webdriver/tests/retrieval/find_element.py::test_xhtml_namespace[link text-full link text]
       imported/w3c/webdriver/tests/retrieval/find_element.py::test_xhtml_namespace[partial link text-link text]
       imported/w3c/webdriver/tests/retrieval/find_elements.py::test_xhtml_namespace[link text-full link text]
       imported/w3c/webdriver/tests/retrieval/find_elements.py::test_xhtml_namespace[partial link text-link text]

* UIProcess/Automation/atoms/FindNodes.js:
(switch):
(tryToFindNode):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (225387 => 225388)


--- trunk/Source/WebKit/ChangeLog	2017-12-01 09:49:10 UTC (rev 225387)
+++ trunk/Source/WebKit/ChangeLog	2017-12-01 09:50:52 UTC (rev 225388)
@@ -1,3 +1,27 @@
+2017-12-01  Carlos Garcia Campos  <[email protected]>
+
+        WebDriver: link and partial links queries don't work in xhtml documents
+        https://bugs.webkit.org/show_bug.cgi?id=180191
+
+        Reviewed by Brian Burg.
+
+        We convert the queries to use xpath, which works for html documents, but it doesn't work for xhtml. In case of
+        xhtml we would need to provide a namespace resolver and elements would need to be prefixed with 'xhtml:'. It's
+        easier to simply iterate the link elements and compare the text.
+
+        Fixes: imported/w3c/webdriver/tests/retrieval/find_element_from_element.py::test_xhtml_namespace[link text-full link text]
+               imported/w3c/webdriver/tests/retrieval/find_element_from_element.py::test_xhtml_namespace[partial link text-link text]
+               imported/w3c/webdriver/tests/retrieval/find_element_from_elements.py::test_xhtml_namespace[link text-full link text]
+               imported/w3c/webdriver/tests/retrieval/find_element_from_elements.py::test_xhtml_namespace[partial link text-link text]
+               imported/w3c/webdriver/tests/retrieval/find_element.py::test_xhtml_namespace[link text-full link text]
+               imported/w3c/webdriver/tests/retrieval/find_element.py::test_xhtml_namespace[partial link text-link text]
+               imported/w3c/webdriver/tests/retrieval/find_elements.py::test_xhtml_namespace[link text-full link text]
+               imported/w3c/webdriver/tests/retrieval/find_elements.py::test_xhtml_namespace[partial link text-link text]
+
+        * UIProcess/Automation/atoms/FindNodes.js:
+        (switch):
+        (tryToFindNode):
+
 2017-11-30  Alex Christensen  <[email protected]>
 
         REGRESSION (r224791): cookies are shared between ephemeral sessions in the same process pool

Modified: trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js (225387 => 225388)


--- trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js	2017-12-01 09:49:10 UTC (rev 225387)
+++ trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js	2017-12-01 09:50:52 UTC (rev 225388)
@@ -35,18 +35,12 @@
         strategy = "css selector";
         query = "[name=\"" + escape(query) + "\"]";
         break;
-    case "link text":
-        strategy = "xpath";
-        query = ".//a[@href][normalize-space(descendant-or-self::text()) = \"" + escape(query) + "\"]";
-        break;
-    case "partial link text":
-        strategy = "xpath";
-        query = ".//a[@href][contains(normalize-space(descendant-or-self::text()), \"" + escape(query) + "\")]";
-        break;
     }
 
     switch (strategy) {
     case "css selector":
+    case "link text":
+    case "partial link text":
     case "tag name":
     case "class name":
     case "xpath":
@@ -70,6 +64,32 @@
                     return ancestorElement.querySelector(query) || null;
                 return Array.from(ancestorElement.querySelectorAll(query));
 
+            case "link text":
+                let linkTextResult = [];
+                for (let link of ancestorElement.getElementsByTagName("a")) {
+                    if (link.text.trim() == query) {
+                        linkTextResult.push(link);
+                        if (firstResultOnly)
+                            break;
+                    }
+                }
+                if (firstResultOnly)
+                    return linkTextResult[0] || null;
+                return linkTextResult;
+
+            case "partial link text":
+                let partialLinkResult = [];
+                for (let link of ancestorElement.getElementsByTagName("a")) {
+                    if (link.text.includes(query)) {
+                        partialLinkResult.push(link);
+                        if (firstResultOnly)
+                            break;
+                    }
+                }
+                if (firstResultOnly)
+                    return partialLinkResult[0] || null;
+                return partialLinkResult;
+
             case "tag name":
                 let tagNameResult = ancestorElement.getElementsByTagName(query);
                 if (firstResultOnly)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to