2

I want to check the value of an attribute that is present in an element.

I have the following Python code:

validkey = False

# Was the key valid.
element = w.find_element_by_id('registerkey_form')

# Is the activation message is shown, meaning it was successful in activation.

if element.get_attribute('style'):

    validkey = True

The problem is the second last line. I want to check for:

style="display:block;"

not just the existence of style itself but the value as well.

Originally it is:

style="display:none;"

I want to check if it is "block".

1 Answer 1

4

If you want to check value of style attribute, try

if element.get_attribute('style') == 'display: block;':
    validkey = True

or better to do it as below:

if element.value_of_css_property('display') == 'block':
    validkey = True
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, the 2nd suggestion worked nicely. It would have taken me a while to figure out that it was this sort of syntax ('display') == 'block'. Python is very different to C languages.
@RvBVakama , yeah, each language has some specifics. AFAIK in JavaScript it's also would be ('display') == 'block'... but there is also ('display') === 'block' which really makes me scared :))

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.