Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium web driver if style height 0

I am trying to have a selenium webdriver script do something if the height of a style is 0. I am able to print it using the element.value_of_css_property command but I want to use it as an if statement. So it would be.

If value of height = 0px do one thing. If the value of the height is anything else do the other. Here is the HTML code I am working with.

<div id="computerfilter" class="gridView safari fixed" style="min-width: 110px; overflow: hidden; min-height: 89%;">
 <ul style="position: relative; list-style: none; padding-inline-start: 0px; padding-left: 0px; margin-left: 0px; margin-right: 0px; height: 0px; width: 1000px;"><div style="position: relative; top: 0px;" class="viewport"><li class="lmigrid-row parent expanded" style="cursor: pointer;">

I have tried the following code but Its not working

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if len(self.driver.find_elements(By.CSS_SELECTOR, "ul.computerfilter[style height:0px]")) 

>Solution :

  1. Try either this code:
element = driver.find_element(By.XPATH, "//div[@id='computerfilter']").get_attribute("innerHTML")
print(element)

if "height: 0px" in element:
    print("height is 0")
else:
    print("height is not 0")
  1. Or try this:
element = driver.find_element(By.XPATH, "//div[@id='computerfilter']/ul").get_attribute("style")
print(element)

if "height: 0px" in element:
    print("height is 0")
else:
    print("height is not 0")

Console output:

height is 0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading