Scott Smerchek avatar Scott Smerchek committed 4a62ac9

added :text and :checkbox selectors, added tests for new selectors

Comments (0)

Files changed (2)

pyquery/cssselectpatch.py

         xpath.add_condition("@type = 'radio' and name(.) = 'input'")
         return xpath
 
+    def _xpath_text(self, xpath):
+        """Matches all text input elements.
+        """
+        xpath.add_condition("@type = 'text' and name(.) = 'input'")
+        return xpath
+
+    def _xpath_checkbox(self, xpath):
+        """Matches all checkbox input elements.
+        """
+        xpath.add_condition("@type = 'checkbox' and name(.) = 'input'")
+        return xpath
+
 cssselect.Pseudo = JQueryPseudo
 
 class JQueryFunction(Function):
                 <input name="radio" type="radio" value="one"/>
                 <input name="radio" type="radio" value="two" checked="checked"/>
                 <input name="radio" type="radio" value="three"/>
+                <input name="checkbox" type="checkbox" value="a"/>
+                <input name="checkbox" type="checkbox" value="b" checked="checked"/>
+                <input name="checkbox" type="checkbox" value="c"/>
+                <input name="button" type="button" value="button" />
+                <button>button</button>
               </form>
             </body>
            </html>
         #test on the form
         e = self.klass(self.html4)
         assert len(e(':disabled')) == 1
-        assert len(e('input:enabled')) == 5
+        assert len(e('input:enabled')) == 9
         assert len(e(':selected')) == 1
-        assert len(e(':checked')) == 1
+        assert len(e(':checked')) == 2
         assert len(e(':file')) == 1
-        assert len(e(':input')) == 7
+        assert len(e(':input')) == 12
+        assert len(e(':button')) == 2
         assert len(e(':radio')) == 3
+        assert len(e(':checkbox')) == 3
 
 class TestTraversal(unittest.TestCase):
     klass = pq
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.