Home » Python » python – how to use xpath using variables?-Exceptionshub

python – how to use xpath using variables?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have a project with XML and I am trying to pull specific elements using XPath. Accessing the specific elements (a catalog of plants in this situation) I am using:

for attributes in root.findall("PLANT/[NAME = 'Rose']")

however, in this project, I am using parameters (in pycharm) so instead of using the name rose I need to put a variable in place of it instead. I’ve tried:

root.findall("PLANT/[NAME =" + sys.argv[1] + "]")

But it does not work.

How to&Answers: