I'm having trouble with getting a dynamic element from a website, basically I'm getting input from my user which is later used as input into a website, the name of the element which I want to get afterwards changes based on the input that i got earlier. Therefore the class that i want to find has two possible names, either label label-success or label label-danger. Right now this is the code:
for elem in browser.find_elements_by_xpath('.//span[@class = "label label success"]'):
print elem.text
But whenever i get input from the user that changes the class name to label label-danger I am getting below error
StaleElementReferenceException: Message: {"errorMessag "Element does not exist in cache}
my question is: is it possible to do something like:
find_elements_by_xpath[@class = "label label-success" OR @class = "label label-danger"]
if so how? Or is there any other simple solution to this problem? Thank you