@@ -706,6 +706,40 @@ def activate_jquery(self):
706
706
# Since jQuery still isn't activating, give up and raise an exception
707
707
raise Exception ("Exception: WebDriver could not activate jQuery!" )
708
708
709
+ def get_property_value (self , selector , property , by = By .CSS_SELECTOR ,
710
+ timeout = settings .SMALL_TIMEOUT ):
711
+ """ Returns the property value of a page element's computed style.
712
+ Example:
713
+ opacity = self.get_property_value("html body a", "opacity")
714
+ self.assertTrue(float(opacity) > 0, "Element not visible!") """
715
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
716
+ timeout = self ._get_new_timeout (timeout )
717
+ if page_utils .is_xpath_selector (selector ):
718
+ by = By .XPATH
719
+ if page_utils .is_link_text_selector (selector ):
720
+ selector = page_utils .get_link_text_from_selector (selector )
721
+ by = By .LINK_TEXT
722
+ self .wait_for_ready_state_complete ()
723
+ page_actions .wait_for_element_present (
724
+ self .driver , selector , by , timeout )
725
+ try :
726
+ selector = self .convert_to_css_selector (selector , by = by )
727
+ except Exception :
728
+ # Don't run action if can't convert to CSS_Selector for JavaScript
729
+ raise Exception (
730
+ "Exception: Could not convert {%s}(by=%s) to CSS_SELECTOR!" % (
731
+ selector , by ))
732
+ selector = self .jq_format (selector )
733
+ script = ("""var $elm = document.querySelector('%s');
734
+ $val = window.getComputedStyle($elm).getPropertyValue('%s');
735
+ return $val;"""
736
+ % (selector , property ))
737
+ value = self .execute_script (script )
738
+ if value is not None :
739
+ return value
740
+ else :
741
+ return "" # Return an empty string if the property doesn't exist
742
+
709
743
def bring_to_front (self , selector , by = By .CSS_SELECTOR ):
710
744
""" Updates the Z-index of a page element to bring it into view.
711
745
Useful when getting a WebDriverException, such as the one below:
0 commit comments