Skip to content

Instantly share code, notes, and snippets.

@boatcoder
Created September 29, 2020 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boatcoder/9a9f5e68c4d9701526f83f7ff89572f7 to your computer and use it in GitHub Desktop.
Save boatcoder/9a9f5e68c4d9701526f83f7ff89572f7 to your computer and use it in GitHub Desktop.
Original code from the Selenium documentation of PageObjects in Python
from selenium.webdriver.support.ui import WebDriverWait
class BasePageElement(object):
"""Base page class that is initialized on every page object class."""
def __set__(self, obj, value):
"""Sets the text to the value supplied"""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element_by_name(self.locator))
driver.find_element_by_name(self.locator).clear()
driver.find_element_by_name(self.locator).send_keys(value)
def __get__(self, obj, owner):
"""Gets the text of the specified object"""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element_by_name(self.locator))
element = driver.find_element_by_name(self.locator)
return element.get_attribute("value") # I don't think this belongs here.....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment