Question

I am trying to get the class of a dl-element. I can print the class (see the first line) but i cant use that result in an if-statement (So "works" is never printed). I guess i am somehow wrong with my syntax. Am i? Believe me that there are lot of "method"-class elements in my tests - see below

 print(child.dl.get('class'))
    if child.dl.get('class')=="['method']":
        print("WORKS!")

This is the output of the first line:

['method']
['method']
['class']
['method']
['method']
['method']
['method']
['describe']
Was it helpful?

Solution

child.dl.get('class') returns a list since class is a multi-valued attribute.

Check if method is inside the list:

if 'method' in child.dl.get('class', []):
    print("WORKS!")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top