{"id":21611196,"url":"https://github.com/crocofactory/croco-selenium","last_synced_at":"2025-04-11T05:33:06.007Z","repository":{"id":213301894,"uuid":"717708242","full_name":"CrocoFactory/croco-selenium","owner":"CrocoFactory","description":"The package providing ways to interact with Selenium Web Driver actions, such as clicking, sending keys etc.","archived":false,"fork":false,"pushed_at":"2024-09-23T16:32:08.000Z","size":44,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T03:34:11.483Z","etag":null,"topics":["degen","selenium","web3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/croco-selenium/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CrocoFactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-12T10:33:59.000Z","updated_at":"2024-09-23T16:32:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"e228db06-fcc1-4bf0-9e1d-2bae01e78bf9","html_url":"https://github.com/CrocoFactory/croco-selenium","commit_stats":null,"previous_names":["blnkoff/croco-selenium","crocofactory/croco-selenium"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fcroco-selenium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fcroco-selenium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fcroco-selenium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fcroco-selenium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrocoFactory","download_url":"https://codeload.github.com/CrocoFactory/croco-selenium/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248347391,"owners_count":21088636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["degen","selenium","web3"],"created_at":"2024-11-24T21:11:23.761Z","updated_at":"2025-04-11T05:33:05.973Z","avatar_url":"https://github.com/CrocoFactory.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# croco-selenium\n\n\u003ca href=\"https://github.com/CrocoFactory\"\u003e\u003cimg alt=\"Croco Logo\" src=\"https://raw.githubusercontent.com/CrocoFactory/.github/main/branding/logo/bookmark_rounded.png\" width=\"100\"\u003e\u003c/a\u003e\n\n[![PyPi Version](https://img.shields.io/pypi/v/croco-selenium)](https://pypi.org/project/croco-selenium/)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/croco-selenium?label=downloads)](https://pypi.org/project/croco-selenium/)\n[![License](https://img.shields.io/github/license/CrocoFactory/croco-selenium.svg)](https://pypi.org/project/croco-selenium/)\n[![Last Commit](https://img.shields.io/github/last-commit/CrocoFactory/croco-selenium.svg)](https://pypi.org/project/croco-selenium/)\n[![Development Status](https://img.shields.io/pypi/status/croco-selenium)](https://pypi.org/project/croco-selenium/)           \n\nThe package providing ways to interact with Selenium Web Driver actions, such as clicking, sending keys etc.\n    \n- **[Bug reports](https://github.com/CrocoFactory/croco-selenium/issues)**\n- **[Actions Overview](#actions-overview)**\n\nWhen we use Selenium, it's not convenient to use WebDriverWait with its cluttered chain actions. Instead of many imports \nand instances (By, WebDriverWait, expected_conditions) you can use fast and robust actions.\n\nPackage's source code is made available under the [MIT License](LICENSE)\n\nThe project is made by the **[Croco Factory](https://github.com/CrocoFactory)** team\n\n# Quick Start\n     \nYou can use actions, by the following way.\n\n```python\nfrom selenium.webdriver.chrome.webdriver import WebDriver\nfrom croco_selenium import click\ndriver = WebDriver()\nclick(driver, 10, '//input[@type=\"submit\"]')\n```\n\nIf you don't want to pass driver every using of actions, you can create an instance of ActionPerformer\n\n```python\nfrom selenium.webdriver.chrome.webdriver import WebDriver\nfrom croco_selenium import ActionPerformer\ndriver = WebDriver()\naction_performer = ActionPerformer(driver)\ntimeout = 10\n\naction_performer.send_keys(timeout, '//input[@type=\"password\"]', 'password')\naction_performer.click(timeout, '//input[@type=\"submit\"]')\n```\n\nOne of the best ways to use actions is create an instance of ChromeDriver and perform \nactions by calling methods on it. That class derived from ActionPerformer and ChromiumDriver\n\n```python\nimport os\nfrom croco_selenium import ChromeDriver, Proxy\nproxy = Proxy(host='123.89.46.72', port=8000, username='croco', password='webDriver')\nproject_dir = os.path.dirname(os.path.abspath(__file__))\nextension_paths = [os.path.join(project_dir, 'extensions/metamask.crx')]\n\ndriver = ChromeDriver(proxy=proxy, extension_paths=extension_paths)\ndriver.get('https://facebook.com')\ndriver.send_keys(15, '//input[@id=\"email\"]', 'hello@world.com')\n```\n\n# Actions Overview\nYou can perform the following [actions](#actions), using croco-selenium:\n\n- **[add_cookies](#add_cookies)**\n- **[click](#click)**\n- **[close_tabs](#close_tabs)**\n- **[get_element](#get_element)**\n- **[get_elements](#get_elements)**\n- **[get_element_attribute](#get_element_attribute)**\n- **[get_element_text](#get_element_text)**\n- **[send_keys](#send_keys)**\n- **[silent_send_keys](#silent_send_keys)**\n- **[switch_to_another_window](#switch_to_another_window)**\n- **[switch_to_frame](#switch_to_frame)**\n- **[switch_to_parent_frame](#switch_to_parent_frame)**\n- **[wait_for_invisibility](#wait_for_invisibility)**\n- **[wait_for_windows](#wait_for_windows)**\n\nAnd there are 3 useful [decorators](#decorators):\n\n- **[handle_pop_up](#handle_pop_up)**\n- **[handle_in_new_tab](#handle_in_new_tab)**\n- **[handle_new_tab](#handle_new_tab)**\n         \n## Actions\n\n\u003ch3 id=\"add_cookies\"\u003eadd_cookies\u003c/h3\u003e\nAdds cookies to a current page. It takes valid string containing json, list of cookies or one cookie as dictionary.\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ncookies = '{\"domain\":\".facebook.com\",\"expirationDate\":1689249734,\"httpOnly\":true,\"name\":\"c_user\",\"path\":\"/\",\"secure\":true,\"value\":\"100083466604886\"}'\ndriver.get('facebook.com')\ndriver.add_cookies(cookies)\n```\n\n\u003ch3 id=\"click\"\u003eclick\u003c/h3\u003e\nClicks on element in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\ndriver.click(timeout, '//input[@type=\"submit\"]')\n```\n\n\u003ch3 id=\"close_tabs\"\u003eclose_tabs\u003c/h3\u003e\nCloses all tabs in browser. It's convenient to use, when you add extensions to your browser and their windows occur with \nstarting a driver.\n\n```python\nimport os\nfrom croco_selenium import ChromeDriver\n\nproject_dir = os.path.dirname(os.path.abspath(__file__))\nextension_paths = [os.path.join(project_dir, 'extensions/metamask.crx')]\n\ndriver = ChromeDriver(extension_paths=extension_paths)\ndriver.close_tabs()\ndriver.get('https://facebook.com')\ndriver.send_keys(15, '//input[@id=\"email\"]', 'hello@world.com')\n```\n\n\u003ch3 id=\"get_element\"\u003eget_element\u003c/h3\u003e\nReturns an element in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\nelement = driver.get_element(timeout, '//input[@type=\"submit\"]')\nelement.click()\n```\n\n\u003ch3 id=\"get_elements\"\u003eget_elements\u003c/h3\u003e\nReturns an elements in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\nelements = driver.get_elements(timeout, '//input')\n\nfor element in elements:\n    element.click()\n```\n\n\u003ch3 id=\"get_element_attribute\"\u003eget_element_attribute\u003c/h3\u003e\nReturns an element's attribute in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\nassert driver.get_element_attribute(timeout, '//input[@type=\"checkbox\"]', 'checked')\n```\n\n\u003ch3 id=\"get_element_text\"\u003eget_element_text\u003c/h3\u003e\nReturns element's text in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\nprint(driver.get_element_text(timeout, '//h1'))\n```\n\n\u003ch3 id=\"send_keys\"\u003esend_keys\u003c/h3\u003e\nSends keys in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.send_keys(timeout, '//input[@type=\"password\"]', 'password')\ndriver.click(timeout, '//input[@type=\"submit\"]')\n```\n\n\u003ch3 id=\"silent_send_keys\"\u003esilent_send_keys\u003c/h3\u003e\nSends keys with delay between characters in browser. It's convenient to use when you would like to hide your bot activity\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.silent_send_keys(timeout, '//input[@type=\"password\"]', 'password')\ndriver.click(timeout, '//input[@type=\"submit\"]')\n```\n\n\u003ch3 id=\"switch_to_another_window\"\u003eswitch_to_another_window\u003c/h3\u003e\nSwitches to a different window from current window in browser. It's convenient to use, when you have two windows to be handled\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.silent_send_keys(timeout, '//input[@type=\"password\"]', 'password')\ndriver.click(timeout, '//input[@type=\"submit\"]')\ndriver.switch_to_another_window(timeout)\n\ndriver.click(timeout, '//input[@type=\"submit\"]')\ndriver.switch_to_another_window(timeout)\n```\n\n\u003ch3 id=\"switch_to_frame\"\u003eswitch_to_frame\u003c/h3\u003e\nSwitches to the frame\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.switch_to_frame(timeout, '//iframe[@data-hcaptcha-widget-id]')\ndriver.click(timeout, '//input[@type=\"submit\"]')\n```\n\n\u003ch3 id=\"switch_to_parent_frame\"\u003eswitch_to_parent_frame\u003c/h3\u003e\nSwitches to the parent frame\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.switch_to_frame(timeout, '//iframe[@data-hcaptcha-widget-id]')\ndriver.click(timeout, '//input[@type=\"submit\"]')\ndriver.switch_to_parent_frame()\n```\n\n\u003ch3 id=\"wait_for_invisibility\"\u003ewait_for_invisibility\u003c/h3\u003e\nWait for element's invisibility in browser\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.click(timeout, '//button')\ndriver.wait_for_invisibility(timeout, '//*[@id=\"popup\"]')\n```\n      \n\u003ch3 id=\"wait_for_windows\"\u003ewait_for_windows\u003c/h3\u003e\nWait for occurring of number of windows\n\n```python\nfrom croco_selenium import ChromeDriver\n\ntimeout = 10\ndriver = ChromeDriver()\n\ndriver.wait_for_windows(timeout, 2)\n```\n\n## Decorators\n\u003ch3 id=\"handle_pop_up\"\u003ehandle_pop_up\u003c/h3\u003e\nSwitches to another window, performs decorated function and switches back. Pop up has to be closed after performing\ndecorated function.\n\nThis decorator is usually used for browser extensions' pop-ups. Example of function performing\na third-party Metamask connection:\n\n```python\nfrom croco_selenium import ChromeDriver, handle_pop_up\nfrom selenium.common import TimeoutException\n\n@handle_pop_up()\ndef connect(driver: ChromeDriver, password: str) -\u003e None:\n    try:\n        password_xpath = '//*[@id=\"password\"]'\n        driver.send_keys(7, password_xpath, password)\n\n        unlock_xpath = '//button[@data-testid=\"unlock-submit\"]'\n        driver.click(5, unlock_xpath)\n    except TimeoutException:\n        pass\n\n    for _ in range(3):\n        next_xpath = '//button[@data-testid=\"page-container-footer-next\"]'\n        driver.click(10, next_xpath, ignored_exceptions=TimeoutException)\n```\n\n\u003ch3 id=\"handle_in_new_tab\"\u003ehandle_in_new_tab\u003c/h3\u003e\nOpens new tab, performs decorated function, closes new tab and switches back. Here is example of function performing \ngetting of 2FA code from browser extension.\n\n```python\nfrom croco_selenium import ChromeDriver, handle_in_new_tab\n\n@handle_in_new_tab()\ndef get_code(driver: ChromeDriver, account) -\u003e str:\n    timeout = 15\n\n    driver.get('\u003cEXTENSION_URL\u003e')\n\n    code_field_xpath = '//*[contains(@class, \"code\")]'\n    code_fields = driver.get_elements(timeout, code_field_xpath)\n\n    code_field = code_fields[account.id]\n\n    code = code_field.text\n    return code\n```\n\n\u003ch3 id=\"handle_new_tab\"\u003ehandle_new_tab\u003c/h3\u003e\nPerforms decorated function in new tab and switches back. New tab has to be opened during performing decorated function.\n\n\n# Installing croco-selenium\n\nTo install the package from PyPi you can use:   \n\n```sh\npip install croco-selenium\n```\n   \nTo install the package from GitHub you can use:\n\n```sh\npip install git+https://github.com/CrocoFactory/croco-selenium.git\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrocofactory%2Fcroco-selenium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrocofactory%2Fcroco-selenium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrocofactory%2Fcroco-selenium/lists"}