Q:

Need to change the child node attribute value by finding the parent node in XML

I have an XML file, I need to find the particular parent node by its attribute value and change the child node value accordingly 
I have used the below code to do it. But it is changing the parent node attribute value.  I know the reason, why it is happening but I am not able to find the solution to it. 
import xml.etree.ElementTree as ET
tree=ET.parse("EditedPT.xml")
root = tree.getroot()
for child in root:
    if child.attrib["name"] == "JobStrings":
        child.set("name","Test")
tree.write(open("EditedPT1.xml", 'w'), encoding='unicode')

XML[A dummy XML File]
<?xml version="1.0" encoding="UTF-8"?>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1">
    <Feature name="Job">
        <Option name="Use"/>
    <Feature>
    <Feature name="Job1">
        <Option name="Use"/>
    <Feature>
</Test>

Now, I need to find the node which has attribute name as Job and change the child node Option name="Use" to Option name=" working"

A:

Below
import xml.etree.ElementTree as ET

xmlstring = '''<?xml version="1.0" encoding="UTF-8"?>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1">
    <Feature name="Job">
        <Option name="Use"/>
    </Feature>
    <Feature name="Job1">
        <Option name="Use"/>
    </Feature>
</Test>'''

root = ET.fromstring(xmlstring)
features = root.findall('.//Feature/[@name="Job"]')
for feature in features:
    feature.find('.//Option').attrib['name'] = 'working'

tree_as_str = ET.tostring(root, encoding='utf8', method='xml')
print(tree_as_str)

output
b'<?xml version=\'1.0\' encoding=\'utf8\'?>\n<Test version="1">\n    <Feature name="Job">\n        <Option name="working" />\n    </Feature>\n    <Feature name="Job1">\n        <Option name="Use" />\n    </Feature>\n</Test>'

