2024-08-21 19:26:08 +05:30
|
|
|
from selenium.common import TimeoutException
|
2024-05-20 17:46:45 +05:30
|
|
|
from selenium.webdriver.support.wait import WebDriverWait
|
|
|
|
|
from selenium.webdriver.support import expected_conditions as ec
|
|
|
|
|
|
2024-08-21 19:26:08 +05:30
|
|
|
from tests.conftest import config
|
|
|
|
|
from utils.CustomException import NoElementFound, TitleNotFound
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_clickable_element(driver, config, By, element_id):
|
|
|
|
|
|
|
|
|
|
try:
|
2024-09-30 12:21:29 +01:00
|
|
|
element = WebDriverWait(driver, timeout=config["timeout"]).until(
|
2024-08-21 19:26:08 +05:30
|
|
|
ec.element_to_be_clickable((By, element_id))
|
|
|
|
|
)
|
|
|
|
|
except TimeoutException:
|
|
|
|
|
# print("NoElement")
|
2024-09-30 12:21:29 +01:00
|
|
|
raise NoElementFound(element_id, config["timeout"])
|
2024-08-21 19:26:08 +05:30
|
|
|
return element
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_element(driver, config, By, element_id):
|
|
|
|
|
try:
|
2024-09-30 12:21:29 +01:00
|
|
|
return WebDriverWait(driver, timeout=config["timeout"]).until(
|
2024-08-21 19:26:08 +05:30
|
|
|
ec.visibility_of_element_located((By, element_id))
|
|
|
|
|
)
|
|
|
|
|
except TimeoutException:
|
|
|
|
|
# print("NoElement")
|
2024-09-30 12:21:29 +01:00
|
|
|
raise NoElementFound(element_id, config["timeout"])
|
2024-08-21 19:26:08 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_invisible_element(driver, config, By, element_id):
|
|
|
|
|
try:
|
2024-09-30 12:21:29 +01:00
|
|
|
return WebDriverWait(driver, timeout=config["timeout"]).until(
|
2024-08-21 19:26:08 +05:30
|
|
|
ec.presence_of_element_located((By, element_id))
|
|
|
|
|
)
|
|
|
|
|
except TimeoutException:
|
|
|
|
|
# print("NoElement")
|
2024-09-30 12:21:29 +01:00
|
|
|
raise NoElementFound(element_id, config["timeout"])
|
2024-08-21 19:26:08 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_title(driver, config, title):
|
|
|
|
|
try:
|
2024-09-30 12:21:29 +01:00
|
|
|
return WebDriverWait(driver, timeout=config["timeout"]).until(
|
2024-08-21 19:26:08 +05:30
|
|
|
ec.title_contains(title)
|
|
|
|
|
)
|
|
|
|
|
except TimeoutException:
|
|
|
|
|
# print("NoElement")
|
2024-09-30 12:21:29 +01:00
|
|
|
raise TitleNotFound(title, config["timeout"])
|