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 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 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 setvalue(inputform:form,dic:dict,begin:str,end:str): ''' 通过输入数据XML自动生成表单的赋值语句 :param inputform: 脚本需要的输入值序列 :param dic: 脚本需要的字典 :param begin: 起点 :param end: 结束点 :return: ''' flag = False for (key,value) in dic.items(): #print(key, value) name = key.split('#')[0].split('_')[0] type ='' #输入框的类型,R只读,D默认值 if len(key.split('#'))==2: type = key.split('#')[1] if key==begin or flag : flag = True if 'R' in type: infostr = '检查输入框:{0},是否只读'.format(name) logger.info(infostr) if not readonly(inputform[name]): errorstr = '输入框:{0},只读检查失败'.format(name) logger.error(errorstr) raise ClassSelenium.SeleniumExceptions(errorstr) # 数据检查,如果输入框类型是含有默认值,输入数据不能为空_begin if 'D' in type: if value: infostr = '检查输入框{0}默认值是否为{1}'.format(name,value) logger.info(infostr) inputform.checkvalue(name,value) else: errorstr = '输入框{0}含有默认值,不允许输入数据值为空'.format(key) logger.error(errorstr) raise ClassSelenium.SeleniumExceptions(errorstr) # 数据检查,如果输入框类型是含有默认值,输入数据不能为空_end elif value: if '=' in value: #输入值是字典类型,用于小手 tempdict = {} temps = value.spit(',') for temp in temps: tempdict[temp.split('=')[0]]=temp.split('=')[1] inputform.setvalue(name,tempdict) elif ',' in value: #输入值是多选值 logger.debug(r"inputform.setvalue('{0}','{1}'.split(','))".format(name,value)) inputform.setvalue(name, value.split(',')) #print('inputform.setvalue({0},{1})'.format(key,value)) else: #输入值是正常字符串 logger.debug(r'inputform.setvalue("{0}","{1}")'.format(name,value)) inputform.setvalue(name,value) if key == end: return
def SelectListData(driver,k,v,action='Click'): ''' 通过传入的driver自动获取当前表格,通过k:列名 v:列中字段值,锁定所需的行,然后勾选 :param driver: :param k: :param v: :return: ''' i=1 j=1 finstr = '开始查找表格数据,列名:{0},列值{1},action:{2}'.format(k,v,action) logger.info(finstr) elements=None try: elements=driver.getelementbyattribute('css selector:.hc-datagrid-header>table>tbody>tr>td',getall = True) except: elements = driver.getelementbyattribute('css selector:.hc-datagrid-body>table>thead>tr>td', getall=True) notfindflag = 1 for m in elements: xt = m.gettext() # 获取表头值� if xt == k: notfindflag=0 break i = i + 1 if notfindflag: finstr = '未找到表格数据,列名:{0},列值{1},action:{2}'.format(k, v, action) logger.error(finstr) raise ClassSelenium.SeleniumExceptions(finstr) element1s=driver.getelementbyattribute('css selector:.hc-datagrid-body>table>tbody>tr',getall=True) notfindflag = 1 for n in element1s: try: ts=n.getelementbyattribute('css selector:td:nth-child('+str(i)+')',getall = True) except: if element1s[0].getelementbyattribute('xpath:td', getall=True)[0].gettext() == '暂无数据': finstr = '查询表格数据为空,列名:{0},列值{1},action:{2}'.format(k, v, action) logger.error(finstr) raise ClassSelenium.SeleniumExceptions(finstr) xs=ts[0].gettext() # 获取cell值� if xs==v: notfindflag =0 if action =='Select': ts = n.getelementbyattribute('css selector:td:nth-child('+str(1)+')').Click() else: ts[0].Click() finstr = '找到表格数据,列名:{0},列值{1},action:{2}'.format(k, v, action) logger.info(finstr) break j=j+1 if notfindflag: finstr = '未找到表格数据,列名:{0},列值{1},action:{2}'.format(k, v, action) logger.error(finstr) raise ClassSelenium.SeleniumExceptions(finstr)
def setvalue(self,name,value): ''' 表单输入框的label值,输入到输入框的值 :param name: :param value: :return: ''' try: hand = self.loanform.getelementbyattribute('xpath:descendant::label[@title="{0}"]/following-sibling::div/div/i[@class="fa fa-hand-pointer-o u-autoitem-down"]'.format(name)) except: pass else: hand.Click() tempaddwin = self.driver.getelementbyattribute(r'xpath://body/div[@style="display: block;"][last()]/div[2]') handobject = choosehand(self.driver,tempaddwin) handobject.fastserach(value) return self._getinput(name) cureletype = self._geteletype() if cureletype=='str': self._settextvalue(value) elif cureletype=='calendar': self._setcalendarvalue(value) elif cureletype=='singtree': self._setsingtreevalue(value) elif cureletype=='select': self._setselevalue(value) elif cureletype == 'unknow': errorcureletype = '获取表单输入框{0}属性的时候失败,输入框为未知类型' logger.error(errorcureletype) raise ClassSelenium.SeleniumExceptions(errorcureletype)
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 init(xmlpath): global InputData global UIExcept InputData=collections.OrderedDict() UIExcept=collections.OrderedDict() DOMTree = parse(xmlpath) collection = DOMTree.documentElement if collection.hasAttribute('note'): logger.info('执行案例'+ collection.getAttribute('note')) subs =collection.getElementsByTagName('sub') num = 1 sub = subs[0] logger.info('执行sub{{0}}:{1}'.format(num,sub.getAttribute('id'))) num +=1 ins = sub.getElementsByTagName('inparams')[0].getElementsByTagName('in') uis = sub.getElementsByTagName('UIexcept')[0].getElementsByTagName('in') for i in ins: InputData[i.getAttribute('name')] = i.getAttribute('value') for j in uis: UIExcept[j.getAttribute('name')] = j.getAttribute('value') Lib.买方业务.直接投资.债权投资.UIExcept = UIExcept Lib.买方业务.直接投资.债权投资.InputData = InputData global driver driver=ClassSelenium.ClassSelenium("http://192.168.70.237:8080/am/login.htm,chrome") driver.getelementbyattribute("id:vc_op_code").sendkeys(InputData.get('账号')) driver.getelementbyattribute('id:vc_op_password').sendkeys(InputData.get('密码')) #�� driver.getelementbyattribute('id:login').Click() driver.getelementbyattribute('link text:买方业务').Click()#菜单 driver.getelementbyattribute('link text:直接投资').Click()#菜单 driver.getelementbyattribute('link 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 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 init(): global driver driver=ClassSelenium.ClassSelenium("http://192.168.70.237:8080/am/login.htm,chrome") driver.getelementbyattribute("id:vc_op_code").sendkeys('8888') driver.getelementbyattribute('id:vc_op_password').sendkeys("123456") #�� driver.getelementbyattribute('id:login').Click() driver.getelementbyattribute('link text:系统管理').Click()#菜单 driver.getelementbyattribute('link text:系统配置管理').Click()#菜单 driver.getelementbyattribute('link text:角色管理').Click()#菜单
def _setsingtreevalue(self,value): self.curinputele.Click() self.curinputele.sendkeys(value[:1]) #temp = self.hidediv.getelementbyattribute('tag name:div,style:[\s\S]*display: block;[\s\S]*') temp = self.driver.getelementbyattribute('xpath://div[@class="h_screen"]/following-sibling::div/div[1],style:[\s\S]*display: block;') listele = self.driver.getelementbyattribute(r'xpath:.//span[text()="{0}"]'.format(value)) listele.Click() title = self.curinputele.getattribute('title') if title!=value: raise ClassSelenium.SeleniumExceptions('单选属性选择控件选择值:{0} 不成功'.format(value))
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 checkvalue(self,name,value): self._getinput(name) cureletype = self._geteletype() if cureletype=='calendar': title = self.curinputele.getelementbyattribute('xpath:preceding-sibling::input',getall=True)[0].getattribute('value') else: title = self.curinputele.getattribute('title') if value not in title: errorcureletype = '检查输入框默认值有误,输入框:{0},默认值{1},实际值:{2}'.format(name,value,title) logger.error(errorcureletype) raise ClassSelenium.SeleniumExceptions(errorcureletype)
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 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 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 _setcalendarvalue(self,value): self.curinputele.Click() self.curinputele.clear() xpathstr = 'xpath://div[@class="h_screen"]/following-sibling::div,style:[\s\S]*display: block;[\s\S]*,class:[\s\S]*datetimepicker[\s\S]*' temp = self.driver.getelementbyattribute(xpathstr) self.curinputele.sendkeys(value) self.curinputele.Click() temp.getelementbyattribute('css selector:.day.active').Click() inputdate = self.curinputele.getelementbyattribute('xpath:preceding-sibling::input',getall =True)[0] title = inputdate.getattribute('value') if title != value: raise ClassSelenium.SeleniumExceptions('文本控件输入值:{0} 不成功'.format(value)) self.loanform.Click()
def init(): global driver driver = ClassSelenium.ClassSelenium( "http://192.168.70.237:8080/am/login.htm,chrome") driver.getelementbyattribute("id:vc_op_code").sendkeys('8888') driver.getelementbyattribute('id:vc_op_password').sendkeys("123456") #�� driver.getelementbyattribute('id:login').Click() driver.getelementbyattribute('link text:系统管理').Click() #菜单 driver.getelementbyattribute('link text:系统配置管理').Click() #菜单 #driver.getelementbyattribute('link text:部门管理').Click()#菜单 driver.getelementbyattribute( r"xpath://div[2]/div[1]/div/div[3]/ul/li[13]/ul/li[1]/ul/li[10]/a" ).click()
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 init(): global driver driver=ClassSelenium.ClassSelenium("http://192.168.70.237:8080/am/login.htm,chrome") driver.getelementbyattribute("id:vc_op_code").sendkeys('8888') driver.getelementbyattribute('id:vc_op_password').sendkeys("123456") #�� driver.getelementbyattribute('id:login').Click() driver.getelementbyattribute('link text:系统管理').Click()#菜单 driver.getelementbyattribute('link text:系统配置管理').Click()#菜单 driver.getelementbyattribute('link text:用户管理').Click()#菜单 #获取用户表单 global operatable operatable=driver.getelementbyattribute('tag name:table,id:data_table_dataTable') #获取用户功能菜单 global buttonmenu buttonmenu=driver.getelementbyattribute("xpath:.//*[@id='wrap_dataTable']/div[1]")
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 _setselevalue(self,value): self.curinputele.Click() #temp = self.hidediv.getelementbyattribute('tag name:div,style:[\s\S]*display: block;[\s\S]*') temp = self.driver.getelementbyattribute('xpath:.//div[@id="hc_hide_div"]/div,style:[\s\S]*display: block;[\s\S]*') if temp.getattribute('multiple_line') == 'true': # 如果是多选框执行多选框赋值函数 self._setmulselevalue(value) else: #tempstr = 'xpath:ul/li[@title ="{0}"]'.format(value) value=value.strip() tempstr = 'xpath:ul/li/label' listeles = temp.getelementbyattribute(tempstr, getall=True) for listele in listeles: if value in listele.gettext(): listele.Click() break title = self.curinputele.getattribute('title').strip() if title!=value: raise ClassSelenium.SeleniumExceptions('单选框值:{0} 选择不成功'.format(value))
def _getinput(self,name): # tempstr = 'xpath:descendant::label[@title="{0}"]/following-sibling::*/descendant::*/input[@title]'.format(value) #增加对textarea 类型的支持 try: tempstr = 'xpath:descendant::label[@title="{0}"]/following-sibling::*/descendant::*/input'.format(name) inputlist = self.loanform.getelementbyattribute(tempstr,getall='True') except: tempstr = 'xpath:descendant::label[@title="{0}"]/following-sibling::*/descendant::*/textarea'.format(name) inputlist = self.loanform.getelementbyattribute(tempstr, getall='True') if(len(inputlist) == 1): self.curinputele = inputlist[0] elif(len(inputlist) == 2): self.curinputele = inputlist[1] elif(len(inputlist) == 3): self.curinputele = inputlist[1] else: raise ClassSelenium.SeleniumExceptions("Form有新的输入框类型出现,需要添加功能") return self.curinputele
def search(self,*kw,**kkw): """ 通过输入条件,查询对手方,如果不输入默认为None :param l_rival_id: 对手方序号 :param vc_all_name: 对手方名称 :param vc_rival_type: 对手方类型 :return: 空 """ if kw: if len(self.names)<len(kw): raise ClassSelenium.SeleniumExceptions('输入框和参数数值对应不正确') i = 0 for j in kw: self.sform.setvalue(self.names[0],j) i +=1 elif kkw: for (name,value) in kkw.items(): self.sform.setvalue(name,value) self.sform.button('查询')
def oprightcopy(): SelectListData(driver,'归属部门','webUI') buttonmenu.getelementbyattribute('link text:用户权限复制').Click() addwin=driver.getelementbyattribute(r'xpath://*****:*****@style="display: block;"]/div[2]') addwin.getelementbyattribute('tag name:a,title:关闭').Click() buttonmenu.getelementbyattribute('link text:用户权限复制').Click() # 角色分配窗体 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()]') addwin.getelementbyattribute('tag name:button,text:清空').Click() if notemptycheck(v1,v2): raise ClassSelenium.SeleniumExceptions("角色分配清空操作失败") v1.sendkeys('0001') #v2.sendkeys('3') addwin.getelementbyattribute('tag name:button,text:查询').Click() SelectListData(addwin,'用户编号','0001') addwin.getelementbyattribute('tag name:button,text:权限复制').Click() msgfloat(driver,'确认','请您确认是否提交','取消','用户权限复制') addwin.getelementbyattribute('tag name:button,text:权限复制').Click() msgfloat(driver,'确认','请您确认是否提交','确定','用户权限复制') htips(driver,'操作成功')
def add(self): self.window.getelementbyattribute('link text:新增').Click() time.sleep(1) #addwin = driver.getelementbyattribute(r"xpath:.//*[@id='addWin']",getall =True)[-1] addwin = driver.getelementbyattribute( r'xpath://*****:*****@style="display: block;"][last()]/div[2]') #print(len(a)) self.subform = form(driver, addwin) #addwin.getelementbyattribute('tag name:button,text:确定').Click() if not readonly(self.subform['对手方']): raise ClassSelenium.SeleniumExceptions('对手方字段非只读') self.subform.setvalue('股东名称', 'webUI') self.subform.setvalue('股东类别', '1:个人') self.subform.setvalue('关联关系', '1:大股东') self.subform.setvalue('证件类型', '11:户口簿') self.subform.setvalue('证件号码', '1231231213') self.subform.setvalue('持股比例(%)', '12') self.subform.button('确定') # 弹出提示信息begin msgfloat(driver, '提示', '操作成功', '确定', '股东信息新增')
def modify(self): SelectListData(self.driver, InputData.get("表格列名"), InputData.get("表格列值")) self.downwindow.getelementbyattribute('link text:修改').Click() addwin = driver.getelementbyattribute( r'xpath://body/div[@style="display: block;"]/div[2]') driver.getelementbyattribute('tag name:button,text:取消').Click() self.downwindow.getelementbyattribute('link text:修改').Click() addwin = driver.getelementbyattribute( r'xpath://body/div[@style="display: block;"]/div[2]') loanform = form(driver, addwin) v1 = loanform['对手名称'] v2 = loanform['银行总行'] v3 = loanform['银行账户'] if not readonly(v1, v2, v3): raise ClassSelenium.SeleniumExceptions('对手方账号修改字段非只读') setvalue(loanform, InputData, '银行名称', '是否内部账户') loanform.button('确定') msgfloat(self.driver, '提示', '操作成功', '确定', '对手方账号修改') return