File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -1776,6 +1776,23 @@ def test_find_simple(self):
1776
1776
# Issue #16922
1777
1777
self .assertEqual (ET .XML ('<tag><empty /></tag>' ).findtext ('empty' ), '' )
1778
1778
1779
+ def test_find_xpath (self ):
1780
+ LINEAR_XML = '''
1781
+ <body>
1782
+ <tag class='a'/>
1783
+ <tag class='b'/>
1784
+ <tag class='c'/>
1785
+ <tag class='d'/>
1786
+ </body>'''
1787
+ e = ET .XML (LINEAR_XML )
1788
+
1789
+ # Test for numeric indexing and last()
1790
+ self .assertEqual (e .find ('./tag[1]' ).attrib ['class' ], 'a' )
1791
+ self .assertEqual (e .find ('./tag[2]' ).attrib ['class' ], 'b' )
1792
+ self .assertEqual (e .find ('./tag[last()]' ).attrib ['class' ], 'd' )
1793
+ self .assertEqual (e .find ('./tag[last()-1]' ).attrib ['class' ], 'c' )
1794
+ self .assertEqual (e .find ('./tag[last()-2]' ).attrib ['class' ], 'b' )
1795
+
1779
1796
def test_findall (self ):
1780
1797
e = ET .XML (SAMPLE_XML )
1781
1798
e [2 ] = ET .XML (SAMPLE_SECTION )
You can’t perform that action at this time.
0 commit comments