def queryclass(self, **name): """ 查询班级列表 li:认证大类 le:认证层级 name:班级名称 """ driver = self.driver log.info("开始查询询班级") for key, value in name.items(): print(key, "==>", value) if 'name' in name.keys(): # 输入班级名称 sleep(3) clname = driver.find_element_by_xpath("//div[@id='T_authinfo-authClassMng']//input[@name='classname']") clname.clear() clname.send_keys(name['name']) sleep(3) driver.find_element_by_xpath("//div[@id='T_authinfo-authClassMng']//input[@name='identificationkind']").click() # 选择认证大类 classli = driver.find_elements_by_xpath("//ul[count(li)>=13]/li[%s+1]" % name['li']).pop() classli.click() # 选择认证层级下拉框 driver.find_element_by_xpath("//div[@id='T_authinfo-authClassMng']//input[@name='classlevel']").click() # 选择认证层级 classle = driver.find_elements_by_xpath("//ul[count(li)=4]/li[%s+1]" % name['le']).pop() classle.click() sleep(1) # 点击查询 query = driver.find_element_by_xpath("//div[@id='T_authinfo-authClassMng']//button[span[text()='查询']]") query.click()
def startup(self): log.info("。。。。。。初始化设置。。。。。") global driver self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.driver.maximize_window() driver = self.driver self.url = "http://192.168.68.125:8080/nhr/login/index.action"
def task(self): """填写测评任务和评委 :param self: :return: 无 """ driver = self.driver log.info("开始添加测评任务") # 点击评委通知按钮 driver.find_element_by_xpath(u"//button[span[text()='评委通知']]").click() # 选择测评任务 driver.find_element_by_xpath("//td[@id='authtasktype1-inputCell']").click() # 选择测评任务 driver.find_element_by_xpath(u"//li[text()='认证面谈']").click() sleep(2) # 填写测评名称 tasktext = u'认证面谈%s' % randint(100, 1000) taskname = driver.find_element_by_xpath("//input[@name='taskname']") taskname.send_keys(tasktext) # 调用选择日期控件函数calendar driver.find_element_by_xpath("//table[@id='judgebegintime-triggerWrap']//td[2]").click() calendar(driver, 10, 45, 22, yy=2016, mm=1, dd=5, fg=1) # 填写任务成绩占比 taskratio = driver.find_element_by_xpath("//input[@name='taskratio']") taskratio.clear() taskratio.send_keys(100) ''' # 勾选剔除最高排名 highrank = driver.find_element_by_xpath(u"//label[text()='剔除最高排名']/preceding-sibling::input") highrank.click() # 勾选剔除最低排名 lowrank = driver.find_element_by_xpath(u"//label[text()='剔除最低排名']/preceding-sibling::input") lowrank.click() ''' # 查询评委工号 driver.find_element_by_xpath("//td[@id='mailTo-inputCell']/following-sibling::td").click() # call queryjudges.在查询界面选择评委工号 queryjudges(driver, '119937', '116460', '000120', '000121') # 保存任务 driver.find_element_by_xpath("//button[@id='savejudgebutton-btnEl']").click() # #邮件发送 # inform=driver.find_element_by_xpath("//button[@id='informjudgebutton-btnEl']") # inform.click() # 保存任务成功,点击确定 driver.find_element_by_xpath("//div[contains(@id,'messagebox')]//button[span[text()='确定']]").click() # 返回班级列表界面 driver.find_element_by_xpath("//div[@id='savejudgebutton']/following-sibling::div//button").click()
def menu(self, s=2): log.info("选择菜单节点") sleep(s) self.driver.find_element_by_xpath(u"//div[text()='HR单据申请']").click() sleep(s) self.driver.find_element_by_xpath(u"//div[text()='储备认证管理']").click() sleep(s) self.driver.find_element_by_xpath(u"//div[text()='认证']").click() sleep(s) self.driver.find_element_by_xpath(u"//div[text()='认证开班管理']").click() sleep(s + 1)
def login(self, user="******", password="******"): log.info("启动FireFox浏览器,打开url.") self.driver.get(self.url) log.info("使用账号登陆NHR系统") log.info("登陆账号:" + user) log.info("登陆密码:" + password) self.driver.find_element_by_id("loginName").send_keys(user) self.driver.find_element_by_id("password").send_keys(password) self.driver.find_element_by_class_name("a_login").click()
def queryjudges(driver, *empcode): """ 查询评委工号 """ log.info("开始添加任务评委") # 清空收件人 clearcode = driver.find_elements_by_xpath("//button[span[text()='清空收件人']]") clearcode.pop().click() # 填写部门名称 # dept=driver.find_elements_by_xpath("//input[@name='dept']") # dept.pop().send_keys("FOSS") for emp in range(len(empcode)): # 按工号查询 psn = driver.find_elements_by_xpath("//input[@name='number']") p = psn.pop() p.clear() print(empcode[emp]) p.send_keys(empcode[emp]) # 点击查询 querybtn = "//div[contains(@id,'button') and @style='border-width: 1px; left: 293px; margin:" \ " 0px; top: 0px; width: 75px;']//button[span[text()='查询']]" query = driver.find_elements_by_xpath(querybtn) print(u"查询按钮的元素个数:%s" % len(query)) query.pop().click() sleep(2) # 选择工号 psncode = driver.find_elements_by_xpath("//tr[count(td)=10]/td[1]") psncode.pop().click() # for code in psncode[-10:]: # code.click() # 点击确定 confirmstr = u"//div[em[button[span[text()='清空收件人']]]]/preceding-sibling::div//button[span[text()='确定']]" confirm = driver.find_elements_by_xpath(confirmstr) confirm.pop().click() log.info("评委添加成功") # 点击关闭按钮 close = driver.find_elements_by_xpath("//button[span[text()='关闭']]") print(u"关闭按钮的元素个数:%s" % len(close)) close.pop().click()
def notice(self, stufile="../temp/stuAuthImport.xlsx"): """导入学员 :param stufile:导入学员模板的路径 :param self: :return:无 """ log.info("导入学员") driver = self.driver impfile = os.path.abspath(stufile) # 点击学员通知按钮 notified = driver.find_element_by_xpath(u"//div[@id='T_authinfo-authClassMng']//button[span[text()" u"='学员通知']]") notified.click() ''' # 使用调用au3程序导入学员模板 driver.find_element_by_xpath(u"//button[span[text()='浏览']]").click() # 调用uoloadfile.exe上传文件 sleep(1) bin_home = os.path.abspath('../temp/uploadfile.exe') os.system(bin_home) # os.system("../temp/uploadfile.exe") ''' # 将导入学员模板excel路径输入到浏览按钮 log.info("导入学员模板路径:%s" % os.path.abspath(stufile)) driver.find_element_by_xpath("//input[@name='stuexcel']").send_keys(impfile) # 点击导入按钮 driver.find_element_by_xpath(u"//button[span[text()='导入']]").click() sleep(2) # 导入成功 driver.find_element_by_xpath(u"//body/div[contains(@id,'messagebox')]//button[span[text()='确定']]").click() log.info("导入学员成功,返回班级列表") # 返回班级列表 re = driver.find_element_by_xpath(u"//div[em[button[span[text()='邮件提醒']]]]/following-sibling::div \ //button[span[text()='返回']]") re.click()
def categor(driver, li, le): """ 新增开班,选择认证大类和层级 """ log.info("选择认证大类") # 点击认证大类下拉选择框 ciidenti = driver.find_element_by_xpath(u"//body/div[contains(@id,'ext-comp')]//input[@name='identificationkind']") ciidenti.click() # 选择具体大类//body/div[contains(@id,'boundlist')]//li[text()='IT类'] selarge = driver.find_element_by_xpath("//ul[count(li)=13]/li[%s+1]" % li) selarge.click() log.info("选择认证层级") # 点击认证层级下拉选择框 cileve = driver.find_element_by_xpath(u"//body/div[contains(@id,'ext-comp')]//input[@name='classlevel']") cileve.click() log.info("选择认证层级") # 选择层级 seleve = driver.find_element_by_xpath("//ul[count(li)=4]/li[%s+1]" % le) seleve.click() log.info("填写笔试成绩占比") if le in [0, 1, 2]: # 专业笔试成绩 log.info("填写专业笔试成绩占比") writtenratio = driver.find_element_by_name("writtenratio") writtenratio.clear() if li in range(4, 7): writtenratio.send_keys(0) else: writtenratio.send_keys(20) elif le == 3: # 专业影响力 log.info("填写专业影响力占比") majorratio = driver.find_element_by_name("majorratio") majorratio.clear() majorratio.send_keys(10) else: log.error("填写笔试成绩咱比异常")
def calendar(driver, *dptime, **dpdate): """ 用于选择日历控件选择日期 """ # year,month,day=(2015,11,5) # 切换到日期控件 log.info("切换到日历控件选择日期") frabegin = driver.find_element_by_xpath(u"//*[@width='97' and @height='9']") driver.switch_to_frame(frabegin) # driver.switch_to_frame(0) sleep(1) # 选择日期 log.info("选择日期") if len(dpdate) > 1: sDate = driver.find_element_by_xpath( u"//td[@onclick='day_Click(%s,%s,%s);']" % (dpdate['yy'], dpdate['mm'], dpdate['dd'])) sDate.click() elif dpdate['fg'] != 0: year, month, day = (2015, 11, 5) sDate = driver.find_element_by_xpath(u"//td[@onclick='day_Click(%s,%s,%s);']" % (year, month, day)) sDate.click() # 选择时间 log.info("选择时间") if len(dptime) > 0: hour = driver.find_element_by_xpath("//input[@class='tB']") ActionChains(driver).double_click(hour).perform() hour.send_keys(dptime[0]) mins = driver.find_element_by_xpath("//span[@id='dpTimeStr']/following-sibling::input[3]") ActionChains(driver).double_click(mins).perform() mins.send_keys(dptime[1]) ss = driver.find_element_by_xpath("//span[@id='dpTimeStr']/following-sibling::input[last()]") ActionChains(driver).double_click(ss).perform() ss.send_keys(dptime[2]) # 点击确定 if dpdate['fg']: driver.find_element_by_id("dpOkInput").click() log.info("点击时间控件确定按钮") else: driver.find_element_by_id("dpTodayInput").click() log.info("选择今天时间") # 切换表单 log.info("选择日期结束,结束调用") driver.switch_to_default_content()