def branchdelet(self,opstr): oplist = opstr.split(',') # 为了简化修改,和add保持一致,把list数据进行对掉 chooselist = self.getunchooselist() unchooselist=self.getchooselist() for i in oplist: for j in unchooselist: if i == j[1]: print('找到了',j[1]) j[0].Click() continue raise ClassSelenium.SeleniumError('添加用户:未找到对应用户:',j[1]) self.divdel.Click() afterchooselist = self.getunchooselist() afterunchooselist=self.getchooselist() if (len(unchooselist)-len(afterunchooselist)) == len(oplist) or (len(afterchooselist)-len(chooselist)) == len(oplist): for i in oplist: for j in afterchooselist: if i == j[1]: continue raise ClassSelenium.SeleniumError('添加用户:已选列表未包含对应用户:',j[1]) for i in oplist: for j in afterunchooselist: if i == j[1]: raise ClassSelenium.SeleniumError('添加用户:未选列表仍包含对应用户:',j[1]) else: raise ClassSelenium.SeleniumError('添加用户:添加用户已选和未选数量变化不正确') self.window.getelementbyattribute('tag name:button,text:确定').Click()
def popwindow(driver,vtile,action=None): ''' 封装非标在做相关操作的时候弹出提示框 vtite:弹出标题,支持模糊匹配 vbody:弹出窗提示文本 action:传入按钮文本 error:抛异常文本信息 return:返回弹窗元素 ''' addwin = driver.getelementbyattribute(r'xpath://body/div[@style="display: block;"]/div[2]') title = addwin.getelementbyattribute('tag name:h4').gettext() if vtile in title: logstr = '获取到弹出窗体{0}'.format(title) logger.info(logstr) else: logstr = '获取到弹出窗体{0}失败'.format(vtile) logger.error(logstr) raise ClassSelenium.SeleniumError(logstr) if action: addwin.getelementbyattribute('tag name:button,text:'+action).Click() if addwin.is_displayed(): logstr = '弹出窗体{0}未正常关闭'.format(vtile) logger.error(logstr) raise ClassSelenium.SeleniumError(logstr) return addwin
def branchadd(self,opstr): oplist = opstr.split(',') unchooselist = self.getunchooselist() chooselist=self.getchooselist() print('unchooselist',unchooselist) print('chooselist',unchooselist) for i in oplist: for j in unchooselist: if i == j[1]: print(i,'vs',j[1]) j[0].Click() continue raise ClassSelenium.SeleniumError('添加用户:未找到对应用户:',j[1]) self.divadd.Click() afterunchooselist = self.getunchooselist() afterchooselist=self.getchooselist() if (len(unchooselist)-len(afterunchooselist)) == len(oplist) or (len(afterchooselist)-len(chooselist)) == len(oplist): for i in oplist: for j in afterchooselist: if i == j[1]: continue raise ClassSelenium.SeleniumError('添加用户:已选列表未包含对应用户:',j[1]) for i in oplist: for j in afterunchooselist: if i == j[1]: raise ClassSelenium.SeleniumError('添加用户:未选列表仍包含对应用户:',j[1]) else: raise ClassSelenium.SeleniumError('添加用户:添加用户已选和未选数量变化不正确') self.window.getelementbyattribute('tag name:button,text:确定').Click()
def modifyOp(self): SelectListData(driver, '部门简称', 'webui') self.rightwindow.getelementbyattribute('link text:修改').Click() addwin = driver.getelementbyattribute( r'xpath://*****:*****@style="display: block;"]/div[2]') addwin.getelementbyattribute('tag name:button,text:取消').Click() self.rightwindow.getelementbyattribute('link text:修改').Click() #/html/body/descendant::label[@title="部门编号"]/following-sibling::*/descendant::*/input[last()] v1 = addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门编号"]/following-sibling::*/descendant::*/input[last()]' ) v2 = addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门编码"]/following-sibling::*/descendant::*/input[last()]' ) v3 = addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门简称"]/following-sibling::*/descendant::*/input[last()]' ) v4 = addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门全称"]/following-sibling::*/descendant::*/input[last()]' ) v5 = addwin.getelementbyattribute( r'xpath:descendant::label[@title="创建日期"]/following-sibling::*/descendant::*/input[last()]' ) if not readonly(v1, v5): raise ClassSelenium.SeleniumError("部门修改表单字段属性非只读") v2.clear() v2.sendkeys('3') v3.clear() v3.sendkeys('webui') v4.clear() v4.sendkeys('webui') branchname = "二级部门" a = addwin.getelementbyattribute( r'xpath:descendant::label[@title="上级部门"]/following-sibling::*/descendant::*/input[last()]' ).sendkeys(branchname) treebranch = driver.getelementbyattribute( 'tag name:div,ref_target:ztree_vc_parent_branch_id_edit') treebranch.getelementbyattribute('tag name:span,text:' + branchname).Click() exceptioncheck(addwin) addwin.getelementbyattribute('tag name:button,text:确定').Click() #弹出提示信息begin h_msg_floatdiv = driver.getelementbyattribute('id:h_msg_floatdiv', getall=True)[0] title = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-message-header').gettext() body = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-body-words').gettext() footer = h_msg_floatdiv.getelementbyattribute( 'css selector:.h_btndiv.m-message-footer').gettext() if title != '提示' or body != '操作成功': raise ClassSelenium.SeleniumError("部门修改失败,原因:" + body) h_msg_floatdiv.getelementbyattribute( 'tag name:button,text:确定').Click() #弹出提示信息end self.leftwindow.getelementbyattribute( 'tag name:button,text:查询').Click()
def exceptioncheck(windriver): try: windriver.getelementbyattribute(r'css selector:.verify-tip-inner',getall = True) except Exception as ex: pass else: raise ClassSelenium.SeleniumError("css.verify-tip-inner:"+"输入值有误")
def search(self,value=''): self.upwindow.getelementbyattribute('tag name:button,text:清空').Click() a = self.upwindow.getelementbyattribute(r'xpath:descendant::label[@title="角色名称"]/following-sibling::*/descendant::*/input[last()]') if notemptycheck(a): raise ClassSelenium.SeleniumError("角色搜索清空失败") a.sendkeys(value) self.upwindow.getelementbyattribute('tag name:button,text:查询').Click()
def writeoff(self): SelectListData(driver, '部门简称', 'webui') self.rightwindow.getelementbyattribute('link text:注销').Click() #弹出提示信息begin h_msg_floatdiv = driver.getelementbyattribute('id:h_msg_floatdiv', getall=True)[0] h_msg_floatdiv.getelementbyattribute( 'tag name:button,text:取消').Click() #弹出提示信息end self.rightwindow.getelementbyattribute('link text:注销').Click() #弹出提示信息begin h_msg_floatdiv = driver.getelementbyattribute('id:h_msg_floatdiv', getall=True)[0] title = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-message-header').gettext() body = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-body-words').gettext() footer = h_msg_floatdiv.getelementbyattribute( 'css selector:.h_btndiv.m-message-footer').gettext() if title != '提示' or body != '您确定要注销部门吗': raise ClassSelenium.SeleniumError("部门注销失败,原因:" + body) h_msg_floatdiv.getelementbyattribute( 'tag name:button,text:确定').Click() #弹出提示信息end #弹出提示信息begin h_msg_floatdiv = driver.getelementbyattribute('id:h_msg_floatdiv', getall=True)[0] title = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-message-header').gettext() body = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-body-words').gettext() footer = h_msg_floatdiv.getelementbyattribute( 'css selector:.h_btndiv.m-message-footer').gettext() if title != '提示' or body != '操作成功': raise ClassSelenium.SeleniumError("部门注销失败,原因:" + body) h_msg_floatdiv.getelementbyattribute( 'tag name:button,text:确定').Click() #弹出提示信息begin self.leftwindow.getelementbyattribute( 'tag name:button,text:查询').Click()
def folded(self): self.leftwindow.getelementbyattribute('link text:收缩').Click() try: self.leftwindow.getelementbyattribute( 'tag name:span,class:button level\d* switch noline_open', getall=True, TIMEOUT=5) raise ClassSelenium.SeleniumError("switch noline_close" + "折叠收缩失败") except Exception: pass
def search(self, value=''): self.driver.getelementbyattribute('tag name:button,text:清空').Click() loanform = form(self.driver, self.driver) if notemptycheck(loanform['对手序号'], loanform['对手简称'], loanform['银行账号']): raise ClassSelenium.SeleniumError("角色搜索清空失败") print(InputData) setvalue(loanform, InputData, '对手序号_s', '对手方账户状态_s') self.upwindow.getelementbyattribute('tag name:button,text:查询').Click()
def search(self, value=''): self.driver.getelementbyattribute('tag name:button,text:清空').Click() loanform = form(self.driver, self.driver) if not notemptycheck(loanform['投资明细代码'], loanform['基金代码'], loanform['基金名称'], loanform['投资明细编号'], loanform['投资明细名称']): raise ClassSelenium.SeleniumError("投资业务清空搜索条件失败") setvalue(loanform, InputData, '投资明细代码_s', '投资明细名称_s') self.upwindow.getelementbyattribute('tag name:button,text:查询').Click()
def search(self, value=''): self.upwindow.getelementbyattribute('tag name:button,text:清空').Click() loanform = form(driver, self.upwindow) if notemptycheck(loanform['对手序号']): raise ClassSelenium.SeleniumError("角色搜索清空失败") loanform.setvalue('对手序号', '1233') loanform.setvalue('对手简称', '1233') loanform.setvalue('对手方名称', '1233') loanform.setvalue('行业类别', '1:基础产业') loanform.setvalue('企业特征', '2:大型企业') #loanform.setvalue('对手序号', '1233') self.upwindow.getelementbyattribute('tag name:button,text:查询').Click()
def exceptioncheck(windriver): ''' 检查表单有没有报错提示信息,如果有抛出异常 :param windriver: 需要检查的表单元素 :return: ''' try: windriver.getelementbyattribute(r'css selector:.verify-tip-inner',getall = True) except Exception as ex: pass else: raise ClassSelenium.SeleniumError("css.verify-tip-inner:"+"输入值有误")
def msgfloat(driver,vtile,vbody,action,error='操作失败'): ''' 封装非标在做相关操作的时候弹出提示框 vtite:弹出标题 vbody:弹出窗提示文本 action:传入按钮文本 error:抛异常文本信息 ''' h_msg_floatdiv = driver.getelementbyattribute('id:h_msg_floatdiv',getall=True)[0] title = h_msg_floatdiv.getelementbyattribute('css selector:.m-message-header').gettext() body = h_msg_floatdiv.getelementbyattribute('css selector:.m-body-words').gettext() footer = h_msg_floatdiv.getelementbyattribute('css selector:.h_btndiv.m-message-footer').gettext() if title !=vtile or (vbody not in body): raise ClassSelenium.SeleniumError(error+"失败,原因:"+body) h_msg_floatdiv.getelementbyattribute('tag name:button,text:'+action).Click()
def addOp(self): self.rightwindow.getelementbyattribute('link text:新增').Click() addwin = driver.getelementbyattribute( r'xpath://*****:*****@style="display: block;"]/div[2]') addwin.getelementbyattribute('tag name:button,text:取消').Click() self.rightwindow.getelementbyattribute('link text:新增').Click() #/html/body/descendant::label[@title="部门编号"]/following-sibling::*/descendant::*/input[last()] addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门编号"]/following-sibling::*/descendant::*/input[last()]' ).sendkeys('3') addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门编码"]/following-sibling::*/descendant::*/input[last()]' ).sendkeys("3") addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门简称"]/following-sibling::*/descendant::*/input[last()]' ).sendkeys("webui") addwin.getelementbyattribute( r'xpath:descendant::label[@title="部门全称"]/following-sibling::*/descendant::*/input[last()]' ).sendkeys("webui") a = addwin.getelementbyattribute( r'xpath:descendant::label[@title="上级部门"]/following-sibling::*/descendant::*/input[last()]' ).sendkeys("二级部门") treebranch = driver.getelementbyattribute( 'tag name:div,ref_target:ztree_vc_parent_branch_id') treebranch.getelementbyattribute('tag name:span,text:二级部门').Click() exceptioncheck(addwin) addwin.getelementbyattribute('tag name:button,text:确定').Click() #弹出提示信息begin h_msg_floatdiv = driver.getelementbyattribute('id:h_msg_floatdiv', getall=True)[0] title = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-message-header').gettext() body = h_msg_floatdiv.getelementbyattribute( 'css selector:.m-body-words').gettext() footer = h_msg_floatdiv.getelementbyattribute( 'css selector:.h_btndiv.m-message-footer').gettext() if title != '提示' or body != '操作成功': raise ClassSelenium.SeleniumError("部门增加失败,原因:" + "body") h_msg_floatdiv.getelementbyattribute( 'tag name:button,text:确定').Click() #弹出提示信息end self.leftwindow.getelementbyattribute( 'tag name:button,text:查询').Click()
def modify(self): SelectListData(driver,'角色名称','3') self.downwindow.getelementbyattribute('link text:修改').Click() addwin=driver.getelementbyattribute(r'xpath://*****:*****@style="display: block;"]/div[2]') addwin.getelementbyattribute('tag name:button,text:取消').Click() self.downwindow.getelementbyattribute('link text:修改').Click() #/html/body/descendant::label[@title="部门编号"]/following-sibling::*/descendant::*/input[last()] v1 = addwin.getelementbyattribute(r'xpath:descendant::label[@title="角色编号"]/following-sibling::*/descendant::*/input[last()]') v2 = addwin.getelementbyattribute(r'xpath:descendant::label[@title="角色名称"]/following-sibling::*/descendant::*/input[last()]') v3 = addwin.getelementbyattribute(r'xpath:descendant::label[@title="备注"]/following-sibling::*/descendant::*/input[last()]') if not readonly(v1): raise ClassSelenium.SeleniumError("角色编号非只读") v2.clear() v2.sendkeys(3) v3.clear() v3.sendkeys('webui') exceptioncheck(addwin) addwin.getelementbyattribute('tag name:button,text:确定').Click() msgfloat(driver,'确认','请您确认是否提交','取消','角色修改') addwin.getelementbyattribute('tag name:button,text:确定').Click() msgfloat(driver,'确认','请您确认是否提交','确定','角色修改') htips(driver,'操作成功'); self.search()
def clear(self): self.window.getelementbyattribute('tag name:button,text:清空').Click() chooselist=self.getchooselist() if len(chooselist) !=0: raise ClassSelenium.SeleniumError('清空用户信息:清空失败')