-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwait_until_element.py
48 lines (42 loc) · 1.45 KB
/
wait_until_element.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# filename : wait_until_element.py
# description : Class containing methods for finding elements
# author : Ian Ault
# email : [email protected]
# date : 05-19-2022
# version : v1.0
# usage : python main.py
# notes : This file should not be run directly
# license : MIT
# py version : 3.10.2
#==============================================================================
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Wait_Until_Element:
def __init__(self, driver):
self.driver = driver
def wait_until_element(self, selector, locator, timeout=10):
wait = WebDriverWait(self.driver, timeout)
element = wait.until(
EC.presence_of_element_located(
(
selector, locator
)
)
)
return element
def wait_until_elements(self, selector, locator, timeout=10):
wait = WebDriverWait(self.driver, timeout)
elements = wait.until(
EC.presence_of_all_elements_located(
(
selector, locator
)
)
)
return elements
def wait_until_element_by_xpath(self, sequence, timeout=10):
return self.wait_until_element(By.XPATH, sequence, timeout=timeout)
def wait_until_elements_by_xpath(self, sequence, timeout=10):
return self.wait_until_elements(By.XPATH, sequence, timeout=timeout)