def find_elements_using_parent_element(cls,parent_element,element_identifier_name): try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) return parent_element.find_elements((eval(by[0]),by[1])) except webdriver_exceptions.WebDriverException as e: cls.log.exception("Exception thrown in 'get_web_element' method '{}' ".format(e))
def select_check_box_format(cls, element_identifier_name,state,value_to_format): is_selected = False try: __obj_wait_extension = WaitExtensions() by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format != None : # check if there is an option to format by[1] = __val2.format(value_to_format) if (__obj_wait_extension.Wait_for_element_visible(by, 10)): ele = Env_setup.get_driver().find_element(eval(by[0]), by[1]) action_chains.ActionChains(Env_setup.get_driver()).move_to_element(ele).perform() if (state.upper() == "ON"): if ele.is_selected() : cls.log.info("Check box selection is successful '{}'".format(element_identifier_name)) is_selected = True else: ele.click() # if check box is not selected, then select is_selected = True else: # to un select check box ele.click() cls.log.info("Check box is unselected {}".format(element_identifier_name)) except webdriver_exceptions.NoSuchElementException as e: cls.log.exception("Exception thrown in 'select_check_box_format' method '{}' ".format(e)) raise e except Exception as a: cls.log.exception("Exception thrown in 'select_check_box_format' method '{}' ".format(a)) raise a cls.log.exception("Value of 'is_selected' is '{}' ".format(is_selected)) return is_selected
def get_row_count_in_table(self,element_identifier_name): __element_list = [] try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __element_list = Env_setup.get_driver().find_elements_by_xpath(by[1]) return __element_list.__len__() except webdriver_exceptions.NoSuchElementException as e: raise e
def wait_for(cls,element_identifier_name): try: by = Page_elements().get_element_identifier(element_identifier_name) __obj_wait = WaitExtensions() cls.log.info("Waiting for the object.... '{}'".format(element_identifier_name)) if __obj_wait.Wait_for_element_visible(eval(by),10) != False: pass else: raise webdriver_exceptions.NoSuchElementException except Exception as e: cls.log.exception("Exception thrown in 'Wait_for' method '{}'".format(e)) raise e
def get_web_element(cls,element_identifier_name): try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __obj_wait = WaitExtensions() return __obj_wait.Wait_for_element_visible(by,1) except webdriver_exceptions.NoSuchElementException as e: cls.log.exception("Exception thrown in 'get_web_element' method '{}' ".format(e)) raise except webdriver_exceptions.WebDriverException as e: cls.log.exception("Exception thrown in 'get_web_element' method '{}' ".format(e)) raise
def get_column_value(self,element_identifier_name,index_value): try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val1 = by[1].format(index_value) #print (__val1) #element = Env_setup.get_driver().find_element(eval(by[0]), str(__val1)) element = Env_setup.get_driver().find_element_by_xpath(__val1) action_chains.ActionChains(Env_setup.get_driver()).move_to_element(element).perform() return element.text except webdriver_exceptions.NoSuchElementException as e: #traceback.print_exc() raise e
def get_elements_in_list(cls, element_identifier_name, value_to_format=None): cls.log.info("Enter 'get_elements_in_list' method") try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) if value_to_format != None: __val2 = by[1] by[1] = __val2.format(value_to_format) elements = cls.get_driver().find_elements(eval(by[0]), by[1]) return elements except webdriver_exceptions.NoSuchElementException as e: cls.log.exception("Exception thrown in 'get_elements_in_list' method {}".format(e)) raise except Exception as g: cls.log.exception("Exception thrown in 'get_elements_in_list' method {}".format(g)) raise
def get_preceding_sibling_count_ingrid_byXpath(cls,element_identifier_name,col_name = None): try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if col_name == None : __val1 = __val2 else: __val1 = __val2.format(col_name) print ("Formated column xpath value is '{}'".format(__val1)) __element_list = [] __element_list = cls.get_driver().find_elements_by_xpath(__val1) return __element_list.__len__() except webdriver_exceptions.NoSuchElementException as e: raise e
def is_element_displayed_format(cls,element_identifier_name,value_to_format = None): cls.log.info("Enter 'is_element_displayed_format' method") try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format != None : by[1] = __val2.format(value_to_format) cls.log.info("Formatted value of the by is '{}' ".format(by[1])) element = cls.get_driver().find_element(eval(by[0]), by[1]) __is_displayed = element.is_displayed() cls.log.info("'Is displayed' value of '{}' is '{}'".format(element_identifier_name,__is_displayed)) return __is_displayed except Exception: cls.log.exception("'{}' Element is not displayed so returning False".format(element_identifier_name)) return False
def get_web_element_format(cls, element_identifier_name,value_to_format): try: __obj_wait_extensions = WaitExtensions() by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format != None : by[1] = __val2.format(value_to_format) __ele_ = __obj_wait_extensions.Wait_for_element_visible(by, 10) return __ele_ except webdriver_exceptions.NoSuchElementException as e: cls.log.exception("Exception thrown in 'get_web_element_format' method '{}' ".format(e)) raise except webdriver_exceptions.WebDriverException as e: cls.log.exception("Exception thrown in 'get_web_element_format' method '{}' ".format(e)) raise
def get_attribute_values_in_list(cls, element_identifier_name,attribute_name,value_to_format): __local_value_list = [] try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format != None : by[1] = __val2.format(value_to_format) elements = cls.get_driver().find_elements(eval(by[0]),by[1]) for element in elements: __loc_val = element.get_attribute(attribute_name) __local_value_list.append(__loc_val.strip()) return __local_value_list except webdriver_exceptions.NoSuchElementException as e: cls.log.exception("Exception thrown in 'get_attribute_value_of_element' method {}".format(e)) raise except Exception as e: cls.log.exception("Exception thrown in 'get_attribute_value_of_element' method {}".format(e)) raise
def click_on_element_format_javascript(cls, element_identifier_name, value_to_format=None): try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format == None: pass else: by[1] = __val2.format(value_to_format) script = "return $('"+by[1]+"').get(0);" element_obj = cls.get_driver().execute_script(script) cls.click_on_element_using_actions(element_obj) cls.log.exception("Click on element using java script '{}' ".format(script)) except webdriver_exceptions.NoSuchElementException as b: cls.log.exception("Exception thrown in 'click_on_element_format_javascript' method '{}' ".format(b)) raise b except Exception as f: cls.log.exception("Exception thrown in 'click_on_element_format_javascript' method '{}' ".format(f)) raise f
def click_on_element_format(cls,element_identifier_name,value_to_format=None): try: __obj_wait_extension = WaitExtensions() by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format != None : by[1] = __val2.format(value_to_format) cls.log.info("Formatted value for the element '{}' is {}".format(element_identifier_name,by[1])) element = __obj_wait_extension.Wait_for_element_visible(by,10) if element != False: #element = cls.get_driver().find_element(eval(by[0]), by[1]) # find element # action_chains.ActionChains(Env_setup.get_driver()).move_to_element(element).perform() #scroll to element # element.click() # click on element cls.click_on_element_based_on_browser(element) cls.log.info("Click on element '{}' is successful ".format(element_identifier_name)) else: cls.log.info("Element '{}' is not identified ".format(element_identifier_name)) except webdriver_exceptions.NoSuchElementException as b: cls.log.exception("Exception thrown while finding element '{}' in 'click_on_element_format' method".format(element_identifier_name)) raise b except Exception as f: raise f