-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement.py
More file actions
25 lines (22 loc) · 915 Bytes
/
element.py
File metadata and controls
25 lines (22 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#element.py
# Import necessary modules
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
# Define a class for web elements
class BasePageElement:
# Function to set a value for any element on a web page
def __set__(self, obj, value):
driver = obj.driver
WebDriverWait(driver, 10).until(
lambda driver: driver.find_element(By.ID, self.locator)
)
driver.find_element(By.ID, self.locator).clear()
driver.find_element(By.ID, self.locator).send_keys(value)
# Function to get a value from any element on a web page
def __get__(self, obj, owner):
driver = obj.driver
WebDriverWait(driver, 10).until(
lambda driver: driver.find_element(By.ID, self.locator)
)
element = driver.find_element(By.ID, self.locator)
return element.get_attribute("value")