-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanding_page.py
61 lines (53 loc) · 2.2 KB
/
landing_page.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
from selenium.webdriver.common.action_chains import ActionChains
from utilities import wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import logging
from utilities import driver
def from_menu_get_to_list(menu_name, list_name):
"""
Goes to specified menu and clicks on list name
:param menu_name: Str value for menu name to hover over
:param list_name: Str value for list name to open
:return: None
"""
menu_to_hover = wait.until(EC.element_to_be_clickable((By.XPATH, '//a[text()="{}"]'.format(menu_name))))
hover = ActionChains(driver).move_to_element(menu_to_hover)
hover.perform()
recovery = wait.until(EC.element_to_be_clickable((By.XPATH, '//a[text()="{}"]'.format(list_name))))
logging.info('Verified that {} is found in {}'.format(list_name, menu_name))
recovery.click()
def go_to_next_page():
"""
Clicks on next page button and waits for items to refresh
:return: None
"""
items = items_on_current_page()
next_page_elem = wait.until(EC.element_to_be_clickable((By.XPATH, '//li[@title="Next Page"]')))
next_page_elem.click()
wait.until(EC.staleness_of(items[0]))
def items_on_current_page():
"""
Gets all visible items on a page
:return: List of webelements on current page
"""
items_on_page = wait.until(EC.presence_of_all_elements_located((By.XPATH, '//div[@class="item-title"]/a')))
return items_on_page
def search_for_item(item_name):
"""
Searches through all pages in the list for item
:param item_name: Str value for item to find in the list
:return: Selenium webelement object if found otherwise None
"""
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'pager')))
total_pages = len(driver.find_elements_by_xpath('//ul[@class="page-links"]/li'))
while total_pages > 0:
items = items_on_current_page()
for item in items:
if item_name == item.text:
logging.info("Verified that the {} is present in the list".format(item_name))
return item
go_to_next_page()
total_pages -= 1
logging.info("{} is not found".format(item_name))
return None