def checkout(self): """Click on the `Save and Checkout` button""" self.wait.until( EC.element_to_be_clickable( (By.XPATH, self.save_and_checkout_xpath))) scroll_to_element(self.browser, self.SAVE_AND_CHECKOUT()) self.SAVE_AND_CHECKOUT().click()
def delete_all_items(self): """Click on the `Delete All` button""" self.wait.until( EC.element_to_be_clickable( (By.XPATH, self.delete_all_button_xpath))) scroll_to_element(self.browser, self.DELETE_ALL_BUTTON()) self.DELETE_ALL_BUTTON().click() self.browser.switch_to.alert.accept()
def navigate_to_shopping_cart(self): """Navigate to the shopping cart page""" self.wait.until( EC.element_to_be_clickable((By.XPATH, self.shopping_xpath))) scroll_to_element(self.browser, self.SHOPPING_MENU()) ActionChains(self.browser).move_to_element(self.SHOPPING_MENU()).click( self.CHECK_OUT_OPTION()).perform()
def navigate_to_search_page(self): """Navigate to the search page""" self.wait.until( EC.element_to_be_clickable((By.XPATH, self.search_xpath))) scroll_to_element(self.browser, self.SEARCH_MENU()) ActionChains(self.browser).move_to_element(self.SEARCH_MENU()).click( self.IMAGE_RECORD_OPTION()).perform()
def logout(self): """Log out of ICRIS""" self.wait.until( EC.element_to_be_clickable((By.XPATH, self.logout_xpath))) scroll_to_element(self.browser, self.LOGOUT_BUTTON()) self.LOGOUT_BUTTON().click() self.wait.until(EC.alert_is_present()) self.browser.switch_to.alert.accept() self.browser.close()
def deselect_all_items(self): """Deselect all items in the shopping cart""" self.wait.until( EC.element_to_be_clickable((By.NAME, self.select_all_button_name))) if not self.SELECT_ALL_BUTTON().is_selected(): scroll_to_element(self.browser, self.SELECT_ALL_BUTTON()) self.SELECT_ALL_BUTTON().click( ) # Invoked twice to ensure that all documents self.SELECT_ALL_BUTTON().click() # are deselected else: scroll_to_element(self.browser, self.SELECT_ALL_BUTTON()) self.SELECT_ALL_BUTTON().click()
def navigate_to_page(self, page_number): """ Navigate to the specified page on the document index. Parameters ---------- page_number : int The order of the page to navigate to """ self.wait.until( EC.element_to_be_clickable((By.XPATH, self.pages_menu_xpath))) scroll_to_element(self.browser, self.PAGES_MENU()) self.PAGES()[page_number].click() self.PAGES_MENU_GO_BUTTON().click()
def select_in_batch(self, batch_size=10): """ Select a batch of given size from the document listing in the shopping cart Parameters ---------- batch_size : int Size of batch """ for check_box_button_rank in range(1, batch_size + 1, 1): try: CHECK_BOX_BUTTON = self.browser.find_element_by_xpath( self.check_box_buttons_xpath % check_box_button_rank) scroll_to_element(self.browser, CHECK_BOX_BUTTON) CHECK_BOX_BUTTON.click() except: pass
def cart_document(self, document_row): """ Cart document. Parameters ---------- document_row : selenium.webdriver.remote.webelement.WebElement A Selenium WebElement instance representing the HTML element of the row of the document for which the purchase status is to be checked Returns ------- cart_status : bool Boolean specifying whether the carting operation was successful """ cart_result = False main_window = self.browser.current_window_handle try: self.CART_BUTTON(document_row).click() self.browser.switch_to.window(self.browser.window_handles[1]) self.wait.until( EC.element_to_be_clickable( (By.XPATH, self.cart_ok_button_xpath))) scroll_to_element(self.browser, self.CART_OK_BUTTON()) self.CART_OK_BUTTON().click() self.browser.switch_to.window(main_window) cart_result = True except: cart_result = False return cart_result