@@ -83,6 +83,9 @@ def __add_sync_methods(self, element):
8383 element .get_position = lambda : self .__get_position (element )
8484 element .get_html = lambda : self .__get_html (element )
8585 element .get_js_attributes = lambda : self .__get_js_attributes (element )
86+ element .get_attribute = (
87+ lambda attribute : self .__get_attribute (element , attribute )
88+ )
8689 return element
8790
8891 def get (self , url ):
@@ -440,6 +443,12 @@ def __get_js_attributes(self, element):
440443 self .loop .run_until_complete (element .get_js_attributes_async ())
441444 )
442445
446+ def __get_attribute (self , element , attribute ):
447+ try :
448+ return element .get_js_attributes ()[attribute ]
449+ except Exception :
450+ return None
451+
443452 def __get_x_scroll_offset (self ):
444453 x_scroll_offset = self .loop .run_until_complete (
445454 self .page .evaluate ("window.pageXOffset" )
@@ -1013,8 +1022,10 @@ def get_element_attributes(self, selector):
10131022 )
10141023
10151024 def get_element_attribute (self , selector , attribute ):
1016- attributes = self .get_element_attributes (selector )
1017- return attributes [attribute ]
1025+ return self .get_element_attributes (selector )[attribute ]
1026+
1027+ def get_attribute (self , selector , attribute ):
1028+ return self .find_element (selector ).get_attribute (attribute )
10181029
10191030 def get_element_html (self , selector ):
10201031 selector = self .__convert_to_css_if_xpath (selector )
@@ -1774,31 +1785,26 @@ def scroll_to_y(self, y):
17741785 with suppress (Exception ):
17751786 self .loop .run_until_complete (self .page .evaluate (js_code ))
17761787 self .loop .run_until_complete (self .page .wait ())
1777- self .__add_light_pause ()
17781788
17791789 def scroll_to_top (self ):
17801790 js_code = "window.scrollTo(0, 0);"
17811791 with suppress (Exception ):
17821792 self .loop .run_until_complete (self .page .evaluate (js_code ))
17831793 self .loop .run_until_complete (self .page .wait ())
1784- self .__add_light_pause ()
17851794
17861795 def scroll_to_bottom (self ):
17871796 js_code = "window.scrollTo(0, 10000);"
17881797 with suppress (Exception ):
17891798 self .loop .run_until_complete (self .page .evaluate (js_code ))
17901799 self .loop .run_until_complete (self .page .wait ())
1791- self .__add_light_pause ()
17921800
17931801 def scroll_up (self , amount = 25 ):
17941802 self .loop .run_until_complete (self .page .scroll_up (amount ))
17951803 self .loop .run_until_complete (self .page .wait ())
1796- self .__add_light_pause ()
17971804
17981805 def scroll_down (self , amount = 25 ):
17991806 self .loop .run_until_complete (self .page .scroll_down (amount ))
18001807 self .loop .run_until_complete (self .page .wait ())
1801- self .__add_light_pause ()
18021808
18031809 def save_screenshot (self , name , folder = None , selector = None ):
18041810 filename = name
0 commit comments