def by_name(attr_name_value): try: Wait.name(attr_name_value) return session.ice_driver.find_element_by_name( attr_name_value).text # If failed - count the failure and add the error to list of errors. except Exception: errorMsg = "Failed to get text of element " + attr_name_value raise Exception(errorMsg, attr_name_value)
def name(element_name, wait_for_page=False): try: if wait_for_page: Wait.page_has_loaded() Wait.name(element_name) session.ice_driver.find_element_by_name(element_name).click() # If failed - count the failure and add the error to list of errors. except Exception as e: errorMsg = "Failed to click_on on ID " + element_name raise Exception(errorMsg, e)
def value_by_name(attr_name_value, wait_for_page=False): try: if wait_for_page: Wait.page_has_loaded() Wait.name(attr_name_value) return session.ice_driver.find_element_by_name( attr_name_value).get_attribute("value") except Exception: errorMsg = "Failed to get value by name:" + attr_name_value raise Exception(errorMsg, attr_name_value)
def text_by_name(attr_name_value, typed_text, wait_for_page=False): # Send keys to element in UI, by name locator (e.g. type something in # text box). try: if wait_for_page: Wait.page_has_loaded() Wait.name(attr_name_value) session.ice_driver.find_element_by_name(attr_name_value).clear() session.ice_driver.find_element_by_name( attr_name_value).send_keys(typed_text[:-1]) time.sleep(session.wait_until_time_pause) session.ice_driver.find_element_by_name( attr_name_value).send_keys(typed_text[-1:]) # If failed - count the failure and add the error to list of errors. except Exception as e: errorMsg = "Failed to type " + typed_text + " in text box" raise Exception(errorMsg, e)
def login(email, password, expected_element=Constants.Dashboard.Statuses.Title.ID, element_type="id"): try: logger.debug("Verifying and Insert Login page elements:") logger.debug("Insert Email " + email) Wait.name(Constants.Login.Email.NAME, wait_for_page=True) Enter.text_by_name(Constants.Login.Email.NAME, email) logger.debug("Insert Password") Enter.text_by_name(Constants.Login.Password.NAME, password) logger.debug("Click Login Button") Click.css(Constants.SubmitButton.CSS) logger.debug("Login Button clicked") if element_type == 'id': Wait.id(expected_element, True) elif element_type == 'css': Wait.css(expected_element, True) # If failed - count the failure and add the error to list of errors. except Exception as e: errorMsg = "Login FAILED: email=%s password=%s" % (email, password) logger.error(errorMsg) raise Exception(errorMsg, e)
def select_vendor_from_list(vendor): Wait.name(Constants.Signup.Company.NAME) Select( session.ice_driver.find_element_by_name( Constants.Signup.Company.NAME)).select_by_visible_text(vendor)