Last active
September 29, 2020 18:46
-
-
Save boatcoder/0f1ad2f22587f66abc3b3e59cd8bb9ba to your computer and use it in GitHub Desktop.
A better version of a BasePageElement that returns the element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
return driver.find_element_by_name(self.locator) # Return the element instead of the "value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment