Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jenterkin/selenium-page-elements
A library for simplifying page objects.
https://github.com/jenterkin/selenium-page-elements
page-object selenium
Last synced: 8 days ago
JSON representation
A library for simplifying page objects.
- Host: GitHub
- URL: https://github.com/jenterkin/selenium-page-elements
- Owner: jenterkin
- License: mit
- Created: 2017-05-02T03:05:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T00:31:23.000Z (almost 7 years ago)
- Last Synced: 2024-12-18T04:19:21.783Z (about 1 month ago)
- Topics: page-object, selenium
- Language: Python
- Size: 19.5 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Selenium Page Elements
[![Build Status](https://travis-ci.org/jenterkin/selenium-page-elements.svg?branch=master)](https://travis-ci.org/jenterkin/selenium-page-elements)
[![codecov](https://codecov.io/gh/jenterkin/selenium-page-elements/branch/master/graph/badge.svg)](https://codecov.io/gh/jenterkin/selenium-page-elements)
[![PyPI version](https://badge.fury.io/py/selenium-page-elements.svg)](https://badge.fury.io/py/selenium-page-elements)## Installation
```
$ pip install selenium-page-elements
```## Overview
Selenium Page Elements is a thin wrapper around the Selenium python library that aims to make Page Objects quick and easy to create and maintain by allowing you to define and interact with web elements like object attributes.```python
from selenium.webdriver.common.by import By
from page_elements import Element, InputField, CheckBoxclass LoginPage:
url = "http://localhost/login"# Define your elements in your class.
username = InputField(By.ID, 'username')
password = InputField(By.ID, 'password')
stay_signed_in = CheckBox(By.ID, 'stay-signed-in')
login_button = Element(By.XPATH, '//button[contains(text(), "Login")]')def __init__(self, driver):
# Ensure that your page object has a Selenium webdriver in `self.driver`.
self.driver = driverdef open(self):
self.driver.get(LoginPage.url)def login(self, username, password, stay_signed_in=True):
# Use your elements just as you would any Python variable.
self.username = username
self.password = password
self.keep_me_signed_in = stay_signed_in
self.login_button.click()
```The element classes take in a Selenium `By` object and a selector, so you can select any element you would be able to with Selenium.
To check the value of an element simply call the element with `.value()`
```python
login_page = LoginPage(driver)
login_page.username = 'mmario'
print(login_page.username.value()) # prints 'mmario'
```The reason you have to call `.value()` on the element is because Selenium Page Elements simply returns a monkey-patched Selenium `WebElement` instance. The reason for returning the monkey-patched instance is to give you the flexibility that the Selenium library already gives you, while giving you a shortcut for giving you what you want most of the time. For instance, you can check to make sure that an element is visible and then get the value.
```python
assert login_page.username.is_displayed()
assert login_page.username.value() == 'mmario'
```You can also incorporate waits in your page element instantiations.
```python
from selenium.webdriver.support import expected_conditions as ECclass MyPageObject:
my_button = Element(
By.ID,
'input',
wait=EC.presence_of_element_located,
wait_timeout=5)
```