|
| 1 | +**S-TOOL** |
| 2 | + |
| 3 | +.. image:: https://user-images.githubusercontent.com/33047641/125023819-41998700-e09d-11eb-8076-7fad81f98f70.png |
| 4 | + :width: 150 |
| 5 | + |
| 6 | + |
| 7 | +``S-Tool`` is a utility module that provides helpful methods for interacting with Selenium WebDriver in Python |
| 8 | + |
| 9 | +Installation |
| 10 | +^^^^^^^^^^^^ |
| 11 | + |
| 12 | +Installation using PyPi |
| 13 | +----------------------- |
| 14 | + |
| 15 | +.. code:: bash |
| 16 | +
|
| 17 | + pip install s-tool |
| 18 | +
|
| 19 | +
|
| 20 | +Development Setup |
| 21 | +----------------- |
| 22 | + |
| 23 | +.. code:: bash |
| 24 | +
|
| 25 | + # Clone this repository |
| 26 | + git clone https://github.com/Python-World/s-tool.git |
| 27 | +
|
| 28 | + # Go into the repository |
| 29 | + cd sel-kit |
| 30 | +
|
| 31 | + # Install dependencies |
| 32 | + poetry config virtualenvs.in-project true |
| 33 | + poetry install |
| 34 | +
|
| 35 | + # Start Poetry shell |
| 36 | + poetry shell |
| 37 | +
|
| 38 | +
|
| 39 | +
|
| 40 | +Usage |
| 41 | +^^^^^ |
| 42 | + |
| 43 | +* Example Using Context Manager |
| 44 | + |
| 45 | +.. code-block:: python |
| 46 | +
|
| 47 | + """Example code with context manager""" |
| 48 | +
|
| 49 | + from s_tool.core import SeleniumDriver as SBot |
| 50 | +
|
| 51 | + with SBot("firefox", headless=True) as self: |
| 52 | + self.get("https://google.com") |
| 53 | + sessionid = self.session() |
| 54 | + url = self.url() |
| 55 | + cookies = self.cookies() |
| 56 | +
|
| 57 | + # print sessionid,url,cookies |
| 58 | + print(f"\nurl : {url} \nsession : {sessionid}\ncookies : {cookies}\n") |
| 59 | +
|
| 60 | +
|
| 61 | +* Example Using class |
| 62 | + |
| 63 | +.. code-block:: python |
| 64 | +
|
| 65 | + from s_tool.core import SeleniumTools |
| 66 | +
|
| 67 | + class SBot(SeleniumTools): |
| 68 | + """Example Bot using s-tool""" |
| 69 | +
|
| 70 | + def __init__(self, *args, **kwargs): |
| 71 | + super().__init__(*args, **kwargs) |
| 72 | +
|
| 73 | + def run(self): |
| 74 | + """Code to visit url and fetch cookies and basic info""" |
| 75 | + url ="https://example.com" |
| 76 | + self.get(url) |
| 77 | + sessionid = self.sessionid() |
| 78 | + url = self.url() |
| 79 | + cookies = self.cookies() |
| 80 | +
|
| 81 | + # print sessionid,url,cookies |
| 82 | + print(f"\nurl : {url} \nsession : {sessionid}\ncookies : {cookies}\n") |
| 83 | +
|
| 84 | +
|
| 85 | + bot = SBot(browser ="firefox", headless=True) # change headless=False to run with gui mode |
| 86 | + bot.run() |
| 87 | + bot.close() |
| 88 | +
|
| 89 | +
|
| 90 | +Methods |
| 91 | +^^^^^^^ |
| 92 | + |
| 93 | +Here are the public methods available in the SeleniumTools class: |
| 94 | + - get(): Loads a web page with the specified URL or local file or Html Content. |
| 95 | + - url(): Returns the current URL of the page. |
| 96 | + - text(): Returns the source code of the current page. |
| 97 | + - get_driver_sessionid(): Return an session id string. |
| 98 | + - get_locator(): Returns a WebDriver locator based on the given element identifier and identifier type. |
| 99 | + - get_element(): Returns a single element or a list of elements matching the given element identifier and identifier type. |
| 100 | + - fill(): Fills in form elements with the provided values. |
| 101 | + - wait_for_element(): Waits for an element to be present and visible on the page. |
| 102 | + - element_visibility(): Toggles the visibility of an element on the page. |
| 103 | + - cookies(): Returns all cookies present in the current session. |
| 104 | + - set_cookies(): Sets cookies for the current session using a dictionary of cookie key-value pairs. |
| 105 | + - click(): Clicks on the element identified by the given element identifier and identifier type. |
| 106 | + - press_multiple_keys(): Presses multiple keys simultaneously using Selenium. |
| 107 | + - execute_script(): Executes JavaScript code in the context of the current page. |
| 108 | + - parse(): Parses the HTML content of the current page and returns a list of elements matching the given tag name and attribute value. |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +Feel free to refer to the documentation for each method to understand their parameters and usage. |
| 113 | + |
| 114 | +Contributing |
| 115 | +^^^^^^^^^^^^ |
| 116 | + |
| 117 | +Contributions are welcome! If you find any issues or have suggestions for improvement, please create an issue or submit a pull request. |
| 118 | + |
| 119 | +License |
| 120 | +------- |
| 121 | +This project is licensed under the MIT License. |
0 commit comments