1

I would like to change the css of the element as follows. It works fine when:

browser.execute_script(
    "arguments[0].style.display = 'block';",
    browser.find_element_by_xpath("//div[@role='main']/div/div/div["+str(d)+"]/div["+str(r)+"]/div/div[2]")
)

but when I try to add the "!important", the code was not updated:

browser.execute_script(
    "arguments[0].style.display = 'block!important';",
    browser.find_element_by_xpath("//div[@role='main']/div/div/div["+str(d)+"]/div["+str(r)+"]/div/div[2]")
)

1 Answer 1

1

The statement element.style.display = 'block' will only work for setting the value of valid property values. Since 'block !important' is not recognized, it will not be added. !important itself is a declaration.

You can use .setProperty() instead, which will let you add more than the value. Use 'important' as a string and don't add the exclamation point.

browser.execute_script(
    "arguments[0].style.setProperty('display', 'block', 'important');",
    browser.find_element_by_xpath("//div")
    )
Sign up to request clarification or add additional context in comments.

Comments

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.