Skip to content Skip to sidebar Skip to footer

Lxml Find Element By Name, But Use Variable In Search

I have a problem with the find function in lXML. But i think this is more a generic question how to tell that i want to check against the value, not the object reference. So here i

Solution 1:

stepn = 'Design'step = xml_obj.find('.//step/name[text()={}]'.format(stepn)).getparent()

when you use ' ', it's a string , any element in string will be treated as a string, not a variable.

Use format to add variable to string

Post a Comment for "Lxml Find Element By Name, But Use Variable In Search"