Skip to content

Commit df09c6c

Browse files
authored
Merge pull request #57 from chavarera/main
[#56] added functionality to execute JavaScript statement
2 parents 5e66dd0 + ebdc77d commit df09c6c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- Add or modify existing cookies.
3434
- Retrieve current user agent.
3535
- Check Existence of an element on the page.
36+
- Execute JavaScript statment.
3637
- Element Parser
3738
- table Information.
3839
- Retrieve dropdown options in the dictionary.

s_tool/driver.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
hide_show_elements,
1919
is_element,
2020
page_source,
21+
run_js,
2122
set_cookies,
2223
take_screenshot,
2324
visit,
@@ -159,6 +160,7 @@ def _load_methods(self):
159160
self.is_element = partial(is_element, self.driver)
160161
self.set_cookies = partial(set_cookies, self.driver)
161162
self.ua = partial(get_user_agent, self.driver)
163+
self.js = partial(run_js, self.driver)
162164

163165

164166
if __name__ == "__main__":

s_tool/utils.py

+17
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,20 @@ def get_user_agent(driver: webdriver) -> str:
377377
"""
378378

379379
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}")

0 commit comments

Comments
 (0)