File tree 3 files changed +20
-0
lines changed
3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 33
33
- Add or modify existing cookies.
34
34
- Retrieve current user agent.
35
35
- Check Existence of an element on the page.
36
+ - Execute JavaScript statment.
36
37
- Element Parser
37
38
- table Information.
38
39
- Retrieve dropdown options in the dictionary.
Original file line number Diff line number Diff line change 18
18
hide_show_elements ,
19
19
is_element ,
20
20
page_source ,
21
+ run_js ,
21
22
set_cookies ,
22
23
take_screenshot ,
23
24
visit ,
@@ -159,6 +160,7 @@ def _load_methods(self):
159
160
self .is_element = partial (is_element , self .driver )
160
161
self .set_cookies = partial (set_cookies , self .driver )
161
162
self .ua = partial (get_user_agent , self .driver )
163
+ self .js = partial (run_js , self .driver )
162
164
163
165
164
166
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -377,3 +377,20 @@ def get_user_agent(driver: webdriver) -> str:
377
377
"""
378
378
379
379
return driver .execute_script ("return navigator.userAgent" )
380
+
381
+
382
+ def run_js (driver : webdriver , statement : str ) -> str :
383
+ """Execute an javascript statement and return output
384
+
385
+ Args:
386
+ driver (webdriver): selenium webdriver
387
+ statement ([str]): and variable name or an statement to run
388
+
389
+ Returns:
390
+ str: console output in str format
391
+
392
+ Example:
393
+ Fetch URL
394
+ >>run_js(driver,document.URL)
395
+ """
396
+ return driver .execute_script (f"return { statement } " )
You can’t perform that action at this time.
0 commit comments