-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_element.py
46 lines (37 loc) · 1.34 KB
/
find_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
# -*- coding: utf-8 -*-
# filename : find_element.py
# description : Class containing methods for finding elements
# author : Ian Ault
# email : liketoaccess@protonmail.com
# 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.common.exceptions import *
from selenium.webdriver.common.by import By
class Find_Element:
def __init__(self, driver):
self.driver = driver
def find_element(self, selector, sequence):
try:
return self.driver.find_element(selector, sequence)
except NoSuchElementException as exc:
raise NoSuchElementException(self.driver.current_url) from exc
def find_elements(self, selector, sequence):
return self.driver.find_elements(selector, sequence)
def find_element_by_xpath(self, sequence):
return self.find_element(By.XPATH, sequence)
def find_elements_by_xpath(self, sequence):
return self.find_elements(By.XPATH, sequence)
def find_element_by_xpaths(self, *xpaths):
for xpath in xpaths:
try:
data = self.find_element_by_xpath(xpath)
except NoSuchElementException:
continue
if data:
return data
return False