-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathhandy_wrappers.py
65 lines (59 loc) · 1.91 KB
/
handy_wrappers.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'''
Created on May 30, 2018
@author: venkateshwara.d
'''
from selenium.webdriver.common.by import By
class HandyWrappers():
def __init__(self, driver):
self.driver = driver
def getByType(self, locatorType):
locatorType = locatorType.lower()
if locatorType == "id":
return By.ID
elif locatorType == "name":
return By.NAME
elif locatorType == "xpath":
return By.XPATH
elif locatorType == "css":
return By.CSS_SELECTOR
elif locatorType == "classname":
return By.CLASS_NAME
elif locatorType == "linktext":
return By.LINK_TEXT
else:
print("Locator type " + locatorType + " not correct/supported")
return False
def getElement(self, locator, locatorType="id"):
element = None
try:
locatorType = locatorType.lower()
byType = self.getByType(locatorType)
element = self.driver.find_element(byType, locator)
print("Element Found")
except:
print("Element not found")
return element
def isElementPresent(self, locator, byType):
try:
element = self.driver.find_element(byType, locator)
if element is not None:
print("Element Found")
return True
else:
print("Element not found")
return False
except:
print("Element not found")
return False
def elementPresenceCheck(self, locator, byType):
try:
elementList = self.driver.find_elements(byType, locator)
if len(elementList) > 0:
print("Element Found")
return True
else:
print("Element not found")
return False
except:
print("Element not found")
return False