{"id":14978911,"url":"https://github.com/testingrequired/vom","last_synced_at":"2025-04-04T20:44:57.023Z","repository":{"id":50208552,"uuid":"105389094","full_name":"testingrequired/vom","owner":"testingrequired","description":"A library for writing page objects for selenium tests/scripts","archived":false,"fork":false,"pushed_at":"2022-12-08T00:43:40.000Z","size":409,"stargazers_count":2,"open_issues_count":19,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-14T07:31:57.378Z","etag":null,"topics":["automation","python","python27","python3","selenium","selenium-webdriver","test-automation","testing","testing-tools"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/vom/","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/testingrequired.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}},"created_at":"2017-09-30T17:52:41.000Z","updated_at":"2018-03-06T22:04:29.000Z","dependencies_parsed_at":"2023-01-25T01:31:32.463Z","dependency_job_id":null,"html_url":"https://github.com/testingrequired/vom","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testingrequired%2Fvom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testingrequired%2Fvom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testingrequired%2Fvom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testingrequired%2Fvom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testingrequired","download_url":"https://codeload.github.com/testingrequired/vom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249599,"owners_count":20908211,"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":["automation","python","python27","python3","selenium","selenium-webdriver","test-automation","testing","testing-tools"],"created_at":"2024-09-24T13:58:37.323Z","updated_at":"2025-04-04T20:44:56.997Z","avatar_url":"https://github.com/testingrequired.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/testingrequired/vom.svg?branch=master)](https://travis-ci.org/testingrequired/vom)\n[![PyPI version](https://badge.fury.io/py/vom.svg)](https://badge.fury.io/py/vom)\n\n# vom\n\n`vom` (View Object Model) is a library for writing page objects for selenium tests/scripts\n\n## Installation\n\nTested on Python 2.7.x \u0026 3.6.x\n\n```bash\n$ pip install vom\n```\n\n## Usage\n\nDefining view objects is as easy as extending `View`:\n\n```python\nfrom vom import View\n\nclass LoginForm(View):\n    @property\n    def username(self):\n        return self.find_element_by_id(\"username\")\n    \n    @property\n    def password(self):\n        return self.find_element_by_id(\"password\")\n    \n    @property\n    def submit_button(self):\n        return self.find_element_by_css_selector(\"input[type='submit']\")\n```\n\nLets initialize the view object:\n\n```python\nlogin = LoginForm(lambda: driver.find_element_by_id(\"login-form\"))\n```\n\nThe view object is initialized by passing a `Callable[[], WebElement]`. The `WebDriver` instance is object from the `WebElement`. Its a `Callable` because we need to be able to get a fresh reference to the `WebElement` at any time. See [StaleElementReferenceException](http://selenium-python.readthedocs.io/api.html#selenium.common.exceptions.StaleElementReferenceException)\n\nPassing a lambda can be cumbersome. The [`ViewDriver`](#viewdriver) utility class can streamline this.\n\n## Root `WebElement`\n\nThe `WebElement` returned from the `Callable[[], WebElement]` will serve as the root for the view object.\n\n### Method Calls\n\n`View` will proxy all undefined methods to its `WebElement` allowing you to treat them as a super powered `WebElement`.\n\n### Querying\n\nQuerying for a view object's elements can be done with the same methods you use on `WebElement`. All of the results from these calls are then wrapped in a `View`. Custom view object implementations can be passed for advanced logic.\n\n```python\nfrom vom import View\n\nclass OptionComponent(View):\n    @property\n    def switch(self):\n        self.find_element_by_id(\"switch\")\n    \n    def toggle(self):\n        self.switch.click()\n\nclass SearchForm(View):\n    @property\n    def some_search_option(self):\n        self.find_element_by_id(\"some-search-option-id\", OptionComponent)\n\nsearch = SearchForm(lambda: driver.find_element_by_id(\"search-form\"))\nsearch.some_search_option.toggle()\n```\n\n## Utility Methods\n\nThere are a number of utility methods to supplement the `WebElement` methods.\n\n### Find Element/s by Text\n\nSimilar to `find_element/s_by_link_text` \u0026 `find_element/s_by_partial_link_text` but across all tags. They also allow for a custom `selector`.\n\n* `find_elements_by_text(value, selector=\"*\")`\n* `find_element_by_text(value, selector=\"*\")`\n* `find_elements_by_partial_text(value, selector=\"*\")`\n* `find_element_by_partial_text(value, selector=\"*\")`\n\n### Find Input/s\n\n* `find_inputs_by_placeholder(value)`\n* `find_input_by_placeholder(value)`\n\n### Properties\n\n* `title` Return the `WebElement` title property\n* `has_class(value)` Returns if `WebElement` has css class\n\n### Content\n\n* `inner_html` Returns the `innerHTML` of the `WebElement`\n* `outer_html` Returns the `outerHTML` of the `WebElement`\n* `inner_text` Returns the `innerText` of the `WebElement`\n\n### Waiting\n\n* `wait_until_displayed(timeout=10)`\n* `wait_until_not_displayed(timeout=10)`\n\n### Actions\n\n* `focus()` Focus the `WebElement`\n* `blur()` Blur the `WebElement`\n\n### Execute Script\n\nSimilar to `driver.execute_script` but `arguments[0]` is a reference to the `root` element of the `View`.\n\n* `execute_script(script, *args)`\n* `execute_async_script(script, *args)`\n\n### Transform\n\n* `as_select` Return the `WebElement` wrapped in a `Select`\n\n## ViewDriver\n\n`ViewDriver` is a utility class which wraps `WebDriver`. It provides similar `find_element/s` methods that `View` does.\n\n```python\nfrom selenium import webdriver\nfrom vom import ViewDriver\n\nif __name__ == '__main__':\n    options = webdriver.ChromeOptions()\n    options.add_argument(\"--headless\")\n    driver = ViewDriver(webdriver.Chrome(chrome_options=options))\n\n    driver.get(\"http://example.com\")\n\n    login = driver.find_element_by_id(\"login-form\", LoginForm)\n    login.username.send_keys(\"\")\n    login.password.send_keys(\"\")\n    login.submit_buttom.click()\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestingrequired%2Fvom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestingrequired%2Fvom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestingrequired%2Fvom/lists"}