Permalink
Browse files

Implement :checked per the HTML5 spec.

  • Loading branch information...
1 parent 1c12e2a commit de70d4a74caac9ba72f7aa1598a4e16b21aa53b6 @SimonSapin SimonSapin committed Apr 20, 2012
Showing with 12 additions and 5 deletions.
  1. +9 −4 cssselect/tests.py
  2. +3 −1 cssselect/xpath.py
View
13 cssselect/tests.py
@@ -516,11 +516,13 @@ def pcss(main, *selectors, **kwargs):
assert pcss(':visited', html_only=True) == []
assert pcss(':enabled', html_only=True) == [
'link-href', 'tag-anchor', 'nofollow-anchor',
- 'checkbox-unchecked', 'checkbox-checked', 'area-href']
+ 'checkbox-unchecked', 'text-checked', 'checkbox-checked',
+ 'area-href']
assert pcss(':disabled', html_only=True) == [
- 'checkbox-disabled', 'fieldset', 'checkbox-fieldset-disabled']
-
- assert pcss(':checked', html_only=True) == ['checkbox-checked']
+ 'checkbox-disabled', 'checkbox-disabled-checked', 'fieldset',
+ 'checkbox-fieldset-disabled']
+ assert pcss(':checked', html_only=True) == [
+ 'checkbox-checked', 'checkbox-disabled-checked']
def test_select_shakespeare(self):
document = html.document_fromstring(HTML_SHAKESPEARE)
@@ -623,9 +625,12 @@ def count(selector):
<b id="p-b2">guy</b>
<input type="checkbox" id="checkbox-unchecked" />
<input type="checkbox" id="checkbox-disabled" disabled="disabled" />
+ <input type="text" id="text-checked" checked="checked" />
<input type="hidden" />
<input type="hidden" disabled="disabled" />
<input type="checkbox" id="checkbox-checked" checked="checked" />
+ <input type="checkbox" id="checkbox-disabled-checked"
+ disabled="disabled" checked="checked" />
<fieldset id="fieldset" disabled="disabled">
<input type="checkbox" id="checkbox-fieldset-disabled" />
<input type="hidden" />
View
4 cssselect/xpath.py
@@ -514,7 +514,9 @@ def xpath_checked_pseudo(self, xpath):
# FIXME: is this really all the elements?
return xpath.add_condition(
"(@selected and name(.) = 'option') or "
- "(@checked and name(.) = 'input')")
+ "(@checked "
+ "and (name(.) = 'input' or name(.) = 'command')"
+ "and (@type = 'checkbox' or @type = 'radio'))")
def xpath_link_pseudo(self, xpath):
return xpath.add_condition("@href and "

0 comments on commit de70d4a

Please sign in to comment.