Wmeng0 2020-05-10
# Author:BeeLe# -*-coding:utf-8-*-import osimport randomimport timefrom time import sleepimport pywin32_system32from selenium import webdriverfrom selenium.webdriver.support.ui import Selectimport win32guiimport win32confrom SHjinjian import idCardfrom SHjinjian import phonefrom SHjinjian import xingmingidcard = idCard.idcard() #使用包phone = phone.create_phone()#使用包name = xingming.XM()#使用包
# 创建 WebDriver 实例对象,指明使用chrome浏览器驱动driver = webdriver.Chrome(r‘C:\chromedriver.exe‘)# WebDriver 实例对象的get方法 可以让浏览器打开指定网址driver.get(‘https://saobei.lcsw.cn/lcsw‘)driver.maximize_window()driver.implicitly_wait(10)# 根据 class name 选择元素,返回的是 一个列表# 里面 都是class 属性值为 animal的元素对应的 WebElement对象# 登陆driver.find_element_by_id(‘username‘).clear()driver.find_element_by_id(‘username‘).send_keys("******")driver.find_element_by_id(‘password‘).clear()driver.find_element_by_id(‘password‘).send_keys(‘*******‘)driver.find_element_by_id(‘submit‘).click()sleep(3)# 基本信息填写driver.find_element_by_xpath("//li[@id=‘m-sjgl‘]/a").click()# driver.find_element_by_xpath(‘//span[contains(text(), "商户管理")]‘).click()# driver.find_element_by_xpath("商户管理",encoding=‘unicode_escape‘).click()sleep(2)driver.find_element_by_xpath("//li[@id=‘m_pos_tj‘]/a").click()sleep(2)# driver.find_element_by_xpath(‘//span[contains(text(), "商户管理")]‘).click()# driver.find_element_by_link_text("添加商户").click()alert = driver.switch_to.alert# 获取alert的文本内容# print(alert.text)# 接受--选择“确定”alert.accept()# 行业选择select = Select(driver.find_element_by_id("***********"))select.select_by_value("1")sleep(1)select = Select(driver.find_element_by_id("*****"))select.select_by_value("1")sleep(1)select = Select(driver.find_element_by_id("*******"))select.select_by_value("1")sleep(1)# 代理商选择select = Select(driver.find_element_by_id("*******"))# select.select_by_value("1")# select.deselect_by_visible_text("******") #取消选择select.select_by_visible_text("*******")# 商户名称driver.find_element_by_id("merchantname").send_keys("****", random.randint(100, 1000))driver.find_element_by_id("merchantalias").send_keys("*******", random.randint(100, 1000))driver.find_element_by_id("******").send_keys("******", random.randint(100, 1000))sleep(1)# 商户地址select = Select(driver.find_element_by_id("merchantprovince"))select.select_by_value("湖北省")sleep(1)select = Select(driver.find_element_by_id("merchantcity"))# select.deselect_by_index(1)# select.select_by_value("1")select.select_by_visible_text("武汉市")sleep(1)select = Select(driver.find_element_by_id("merchantcounty"))# select.deselect_by_index(7)# select.select_by_value("1")select.select_by_visible_text("******")driver.find_element_by_id("merchantaddress").send_keys("**********")sleep(1)# 上传照片# 脚本要与upload_file.html同一目录# file_path = ‘file:///‘ + os.path.abspath(‘upload_file.html‘)# driver.get(file_path)# 定位上传按钮,添加本地文件# driver.find_element_by_name("file").send_keys(r‘C:\Users\Administrator\Pictures\test.jpg‘)# upload = driver.find_element_by_id("uploader_one31").click()# dialog = win32gui.FindWindow(‘#32770‘, u‘文件上传‘) # 对话框# ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, ‘ComboBoxEx32‘, None)# ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, ‘ComboBox‘, None)# Edit = win32gui.FindWindowEx(ComboBox, 0, ‘Edit‘, None) # 上面三句依次寻找对象,直到找到输入框Edit对象的句柄# button = win32gui.FindWindowEx(dialog, 0, ‘Button‘, None) # 确定按钮Button# win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, r‘C:\Users\Administrator\Pictures\test.jpg‘) # 往输入框输入绝对地址# win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button) # 按button# sleep(2)# 联系人填写driver.find_element_by_id("merchantperson").send_keys(name)driver.find_element_by_id("merchantperson_idnum").send_keys(888888888888)driver.find_element_by_id("merchantemail").send_keys(phone,"@163.com")driver.find_element_by_id("merchantphone").send_keys(phone)sleep(1)driver.find_element_by_xpath("//button[@onclick=‘nextStep(2)‘]").click()sleep(2)# 结算信息driver.find_element_by_id("license_no").send_keys(idcard)driver.find_element_by_id("timeLong1").click()select = Select(driver.find_element_by_id("accounttype"))select.select_by_visible_text("88888888")# 结算人基本信息driver.find_element_by_id("legalname").send_keys(name)driver.find_element_by_id("legalidnum").send_keys(idcard)driver.find_element_by_id("timeLong2").click()driver.find_element_by_id("cardname").send_keys(name)driver.find_element_by_id("cardnum").send_keys(idcard)driver.find_element_by_id("accountphone").send_keys(phone)# 选择结算银行select = Select(driver.find_element_by_id("bankparent"))select.select_by_visible_text("888888888888")select = Select(driver.find_element_by_id("bankprovince"))select.select_by_visible_text("湖北省")select = Select(driver.find_element_by_id("bankcity"))select.select_by_visible_text("武汉市")select = Select(driver.find_element_by_id("cardbank"))select.select_by_visible_text("888888888888")# 费率select = Select(driver.find_element_by_id("wx_fuiourate"))select.select_by_visible_text("888888888888")# 下一步driver.find_element_by_xpath("//button[@onclick=‘nextStep(3)‘]").click()sleep(2)driver.close()driver.quit()