def click_element(self, msg, window_name, object_name,double = False): ''' Generic call to click any type of element. Tries coordinate based clicking if default does not work. ''' logger.debug(msg) prefix = "img" if self.os_check == "Mac": prefix_of_obj = ["lbl","img","btn","chk","txt", "grp"] if window_name.find("frm") == -1 : window_name = "frm" + window_name if object_name[:3] not in prefix_of_obj: object_name = prefix + object_name try: ldtp.selectmenuitem(window_name,"mnuView;mnuasIcons") time.sleep(2) ldtp.selectmenuitem('frmsample','mnuView;mnuCleanUp') time.sleep(2) except: pass try: if not double: success = ldtp.click(window_name, object_name) else: success = ldtp.doubleclick(window_name, object_name) except Exception, e: try: if not double: ldtp.mouseleftclick(window_name, object_name) else: # on mac first time doubleclick does not work at times ldtp.doubleclick(window_name, object_name) except Exception, e: raise AssertionError("Unable to click element: %s" % traceback.format_exc())
def double_click(self, window_name, object_name): """ [Description] Double clicks the row in table whose first column's(0th column) value is same as the contents of the third argument in the function call. :@参数 window_name: :@参数 object_name: :@返回值: 1 on success, else 0 Examples: | *Test Cases* | *Returns* | *Action* | *Argument* | *Argument* | | Example_Test | ${exec_status}= | Double Click | ${window_name} | ${object_name} | """ try: self._info("double click the mouse") return ldtp.doubleclick(window_name, object_name) except LdtpExecutionError: raise LdtpExecutionError("Double Click failed")
def go_to_dir(self, window_name, path): ''' Got to a location in file system via explorer. ''' if self.os_family == "windows": # self.click_element("Go to location: Computer",window_name, 'uknComputer') object_name = "pane3" currWindowName = window_name tempWindowName = window_name if self.os_check == "Win_8": object_name="pane5" try: ldtp.doubleclick(tempWindowName,'tblcFavorites') tempWindowName = 'Favorites' time.sleep(2) ldtp.generatekeyevent("<left>") ldtp.doubleclick(tempWindowName,'tblcLibraries') tempWindowName = 'Libraries' time.sleep(2) ldtp.generatekeyevent("<left>") ldtp.doubleclick(tempWindowName,'tblcComputer') time.sleep(2) except: ldtp.mouseleftclick(tempWindowName,'ptabView') time.sleep(2) ldtp.mouseleftclick(tempWindowName,'uknNavigationpane') time.sleep(2) ldtp.mouseleftclick(tempWindowName,'mnuNavigationpane') time.sleep(2) try: ldtp.doubleclick(tempWindowName,'tblcFavorites') tempWindowName = 'Favorites' ldtp.generatekeyevent("<left>") time.sleep(2) ldtp.doubleclick(tempWindowName,'tblcLibraries') tempWindowName = 'Libraries' ldtp.generatekeyevent("<left>") time.sleep(2) except: pass ldtp.doubleclick(tempWindowName,'tblcComputer') time.sleep(2) tempWindowName = 'Computer' elif self.os_check == "Win_7_Vista_XP": try: ldtp.doubleclick(tempWindowName, "tblcFavorites") tempWindowName = "Favorites" ldtp.generatekeyevent("<left>") time.sleep(2) ldtp.doubleclick(tempWindowName, "tblcLibraries") tempWindowName = 'Libraries' ldtp.generatekeyevent("<left>") time.sleep(2) ldtp.doubleclick(tempWindowName, "tblcComputer") except : ldtp.mouseleftclick(tempWindowName, "btnOrganize") time.sleep(2) ldtp.generatekeyevent("<l>") time.sleep(2) ldtp.generatekeyevent("<n>") time.sleep(2) ldtp.doubleclick(tempWindowName, "tblcFavorites") tempWindowName = "Favorites" ldtp.generatekeyevent("<left>") time.sleep(2) ldtp.doubleclick(tempWindowName, "tblcLibraries") tempWindowName = 'Libraries' ldtp.generatekeyevent("<left>") time.sleep(2) ldtp.doubleclick(tempWindowName, "tblcComputer") time.sleep(2) # self.click_element("Go to location: Computer",window_name, 'tblcComputer', double = True) self.click_element("Click on Address bar pane in explorer","Computer", object_name) ldtp.enterstring("Computer", "txtAddress", r"%s<enter>" % path) if self.os_check == "Win_8": tempWindowName = self.get_window_name_for_path(path) time.sleep(2) ldtp.mouseleftclick(tempWindowName,'ptabHome') time.sleep(2) elif self.os_family == "mac": if window_name.find("frm") == -1 : window_name = "frm" + window_name ldtp.selectmenuitem(window_name,"mnuGo;mnuGotoFolder*" ) path = path.replace("C:","").replace("\\","/") time.sleep(1) self.send_keys_to_current_focused_object("%s<enter>" % path)