@@ -83,6 +83,9 @@ def __add_sync_methods(self, element):
83
83
element .get_position = lambda : self .__get_position (element )
84
84
element .get_html = lambda : self .__get_html (element )
85
85
element .get_js_attributes = lambda : self .__get_js_attributes (element )
86
+ element .get_attribute = (
87
+ lambda attribute : self .__get_attribute (element , attribute )
88
+ )
86
89
return element
87
90
88
91
def get (self , url ):
@@ -440,6 +443,12 @@ def __get_js_attributes(self, element):
440
443
self .loop .run_until_complete (element .get_js_attributes_async ())
441
444
)
442
445
446
+ def __get_attribute (self , element , attribute ):
447
+ try :
448
+ return element .get_js_attributes ()[attribute ]
449
+ except Exception :
450
+ return None
451
+
443
452
def __get_x_scroll_offset (self ):
444
453
x_scroll_offset = self .loop .run_until_complete (
445
454
self .page .evaluate ("window.pageXOffset" )
@@ -1013,8 +1022,10 @@ def get_element_attributes(self, selector):
1013
1022
)
1014
1023
1015
1024
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 )
1018
1029
1019
1030
def get_element_html (self , selector ):
1020
1031
selector = self .__convert_to_css_if_xpath (selector )
@@ -1774,31 +1785,26 @@ def scroll_to_y(self, y):
1774
1785
with suppress (Exception ):
1775
1786
self .loop .run_until_complete (self .page .evaluate (js_code ))
1776
1787
self .loop .run_until_complete (self .page .wait ())
1777
- self .__add_light_pause ()
1778
1788
1779
1789
def scroll_to_top (self ):
1780
1790
js_code = "window.scrollTo(0, 0);"
1781
1791
with suppress (Exception ):
1782
1792
self .loop .run_until_complete (self .page .evaluate (js_code ))
1783
1793
self .loop .run_until_complete (self .page .wait ())
1784
- self .__add_light_pause ()
1785
1794
1786
1795
def scroll_to_bottom (self ):
1787
1796
js_code = "window.scrollTo(0, 10000);"
1788
1797
with suppress (Exception ):
1789
1798
self .loop .run_until_complete (self .page .evaluate (js_code ))
1790
1799
self .loop .run_until_complete (self .page .wait ())
1791
- self .__add_light_pause ()
1792
1800
1793
1801
def scroll_up (self , amount = 25 ):
1794
1802
self .loop .run_until_complete (self .page .scroll_up (amount ))
1795
1803
self .loop .run_until_complete (self .page .wait ())
1796
- self .__add_light_pause ()
1797
1804
1798
1805
def scroll_down (self , amount = 25 ):
1799
1806
self .loop .run_until_complete (self .page .scroll_down (amount ))
1800
1807
self .loop .run_until_complete (self .page .wait ())
1801
- self .__add_light_pause ()
1802
1808
1803
1809
def save_screenshot (self , name , folder = None , selector = None ):
1804
1810
filename = name
0 commit comments