import lxml.etree as et s = 'ac' x = et.fromstring(s) t = x.find('bar').text print(t) if t != 'abc': raise Exception()