0

So I am working with selenium for some automation and I was using get_attribute to compare values to assign whether a variable would be true or false.

So my question is, when I use get_attribute and it returns the value of 'None' ( This is expected since the element I am looking for does not exist), is that value returned as a String? And if it is, then my question would be, why am I unable to compare it as I would any other string.

active_establishment = CRM_driver.find_element_by_xpath('//*[@id="gridBodyTable"]').get_attribute("records")
print(active_establishment)

if active_establishment == 'None':
    party[x].establishment = False
else:
    party[x].establishment = True

active_establishments = None

establishments = True (expected results should be False)

12
  • Hey guys...silly me. So I found a solution to my problem. All I had to do was cast my active_establishment as a string and it works. pythonactive_establishment = str(CRM_driver.find_element_by_xpath('//*[@id="gridBodyTable"]').get_attribute("records")) This means that when get_attribute returns 'None', it is neither a null or a string. So what is it? Commented Apr 26, 2019 at 17:40
  • If the element does not exist you should receive, no such element exception rather None. Not sure how you are getting None here. However, the type is NoneType. Commented Apr 26, 2019 at 17:56
  • You can simplify your last 4 lines to party[x].establishment = active_establishment != 'None'. Commented Apr 26, 2019 at 19:24
  • If you no longer need this question, please delete it. Commented Apr 26, 2019 at 19:24
  • 1
    Hey guys, seems like I can't delete this post since people have invested time to answer it. I do hope this post can help someone else who stumbles upon it :) thank you everyone Commented Apr 26, 2019 at 21:28

1 Answer 1

1

Change the comparison as below.

if active_establishment is None:
    party[x].establishment = False
else:
    party[x].establishment = True
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this is a lot more efficient than casting find_attribute as a string :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.