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

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

Leave a Reply