Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cssselect/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ def xpath_relation_child_combinator(self, left, right):

def xpath_relation_direct_adjacent_combinator(self, left, right):
"""right is a sibling immediately after left; select left"""
xpath = left.add_condition("following-sibling::{}[position() = 1]".format(right.element))
xpath = left.add_condition(
"following-sibling::*[(name() = '{}') and (position() = 1)]".format(right.element)
)
return xpath

def xpath_relation_indirect_adjacent_combinator(self, left, right):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cssselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def xpath(css):
assert xpath("e:has(~ f)") == "e[following-sibling::f]"
assert (
xpath("e:has(+ f)")
== "e[following-sibling::f[position() = 1]]"
== "e[following-sibling::*[(name() = 'f') and (position() = 1)]]"
)
assert xpath('e f') == (
"e/descendant-or-self::*/f")
Expand Down