How to take ownership of elements in a script

Same error: "AttributeError: ‘NoneType’ object has no attribute ‘Id’ ".
Does anybody mind to share the solution?