# encoding=utf-8import testlogin.login as loginimport timeimport randomfrom selenium.webdriver.support.select import Selectnow_time = time.strftime("%Y%m%d", time.localtime(time.time()))search_time = time.strftime("%Y-%m-%d", time.localtime(time.time()))def searchAll(): dr = login.driver """执行查询全部""" dr.execute_script("form_query()") time.sleep(2) searBusinessNum(dr) # 按商机编号查询 searchBusinessName(dr) # 按商机名称查询 searchCustomerName(dr) # 按客户名称查询 searchBeginTime(dr) # 按预计签单时间查询 searchBusinessStatus(dr) # 按商机状态查询 searchApplyName(dr) # 按申请人查询 searchBeginTime(dr) # 按创建时间查询 searchAreaName(dr) # 按国家查询 searchProductName(dr) # 按产品线查询 searchSaleArea(dr) # 按片区查询 return "pass"def searBusinessNum(dr): '''按商机编号查询''' # dr.switch_to_frame("mainConFrame") # dr.find_element_by_id("container") # 按商机编号查询 js1 = "var businessNum=document.getElementById(\"businessNum\");businessNum.style.border=\"2px solid red\";" dr.execute_script(js1) dr.find_element_by_id("businessNum").send_keys(now_time) dr.execute_script("form_query()") resetAll(dr)def searchBusinessName(dr): '''按商机名称查询''' js2 = "var businessName = document.getElementById(\"businessName\");businessName.style.border=\"2px solid red\";" dr.execute_script(js2) dr.find_element_by_id("businessName").send_keys(u"测试数据_" + now_time) dr.execute_script("form_query()") resetAll(dr)def searchCustomerName(dr): """按客户名称查询""" js3 = "var customerName = document.getElementById(\"customerName\");customerName.style.border=\"2px solid red\";" dr.execute_script(js3) dr.find_element_by_id("customerName").send_keys(u"郑州") dr.execute_script("form_query()") resetAll(dr)def searchBeginTime(dr): """按创建时间查询""" dr.find_element_by_xpath('//*[@id="updateForm"]/table/thead/tr[2]/td[2]/span[1]/input[1]').send_keys(search_time) dr.execute_script("form_query()") time.sleep(1) dr.find_element_by_xpath('//*[@id="updateForm"]/table/thead/tr[2]/td[2]/span[2]/input[1]').send_keys(search_time) dr.execute_script("form_query()") resetAll(dr)def searchBusinessStatus(dr): """按商机状态查询""" businessStatus = dr.find_element_by_id("businessStatus") js4 = "var businessStatus = document.getElementById(\"businessStatus\");businessStatus.style.border=\"2px solid red\";" for i in range(1, 7): dr.execute_script(js4) Select(businessStatus).select_by_index(random.randint(1, 7)) dr.execute_script("form_query()") time.sleep(1) resetAll(dr)def searchApplyName(dr): """按申请人查询""" js5 = '$("input[name=applyName]").val("0096");' # 根据工号进行查询 dr.execute_script(js5) dr.execute_script("form_query()") time.sleep(1) resetAll(dr) js6 = '$("input[name=applyName]").val("王梓聪");' # 根据姓名进行查询 dr.execute_script(js6) dr.execute_script("form_query()") time.sleep(1) resetAll(dr)def searchBeginTime(dr): """按创建时间查询""" dr.find_element_by_xpath('//*[@id="updateForm"]/table/thead/tr[3]/td[2]/span[1]/input[1]').send_keys(search_time) dr.execute_script("form_query()") time.sleep(1) dr.find_element_by_xpath('//*[@id="updateForm"]/table/thead/tr[3]/td[2]/span[2]/input[1]').send_keys(search_time) dr.execute_script("form_query()") resetAll(dr)def searchAreaName(dr): """按国家查询""" areaName = '$("input[name=areaName]").val("中国");' dr.execute_script(areaName) areaCode = '$("input[name=areaCode]").val("CN");' dr.execute_script(areaCode) # dr.find_element_by_id("areaId").send_keys("10116") dr.execute_script("form_query()") resetAll(dr)def searchSaleArea(dr): """按片区查询""" saleArea = dr.find_element_by_id("saleArea") js6 = "var saleArea = document.getElementById(\"saleArea\");saleArea.style.border=\"2px solid red\";" for i in range(1, 10): dr.execute_script(js6) Select(saleArea).select_by_index(random.randint(1, 10)) dr.execute_script("form_query()") time.sleep(1) resetAll(dr)def searchProductName(dr): """按产品线查询""" js6 = "var productBigName = document.getElementById(\"productBigName\");productBigName.style.border=\"2px solid red\";" dr.execute_script(js6) js7 = '$("#productBigName").val("集成外购产品")' dr.execute_script(js7) js8 = '$("#productBigId").val("10520")' dr.execute_script(js8) # dr.find_element_by_id("productBigName").send_keys(u"集成外购产品") # dr.find_element_by_id("productBigId").send_keys(u"10520") dr.execute_script("form_query()") resetAll(dr)def resetAll(dr): """清空所有查询条件""" time.sleep(1) dr.execute_script("btn_reset('form_search');form_reset();")