python_selenium简单记录一下

2021-01-24 10:16

阅读:576

标签:属性   enc   system   odi   index   type   get   win   上传   

# Author:BeeLe
# -*-coding:utf-8-*-


import os
import random
import time
from time import sleep
import pywin32_system32
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import win32gui
import win32con
from SHjinjian import idCard
from SHjinjian import phone
from SHjinjian import xingming

idcard = 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()

python_selenium简单记录一下

标签:属性   enc   system   odi   index   type   get   win   上传   

原文地址:https://www.cnblogs.com/lee88888/p/12865582.html


评论


亲,登录后才可以留言!