实现数据驱动批量新增操作

功能逻辑;

1,从文本里面读取身份证

2,读取的身份证循环写入新增信息

知识点:

1,数据读取

2,获取窗口句柄,操作窗口(关闭,切换,刷新等)

3,切换frame

4,循环

代码如下:

 

#coding=utf-8
import random
from selenium import  webdriver
import time
# print("启动浏览器。。。。。")
source=open("文件路径","r")
values=source.readlines()
source.close()

driver=webdriver.Firefox()
print("打开青少年屈光登录页面。。。。。。。。。。")
nowhandle=driver.current_window_handle
print(nowhandle)
url='url'
driver.get(url)
time.sleep(2)
print("输入用户名密码")
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("zhangjiang")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("123456")
driver.find_element_by_id("submitId").click()
print("登录。。。")
time.sleep(3)
driver.find_element_by_xpath("//li[@id='qg']/a/img").click()
print("进入青少年屈光首页。。。。")
time.sleep(2)
# 获取窗口句柄,关掉之前窗口,切换到最新窗口
allhandles=driver.window_handles
for handle in allhandles:
    print(driver.title)
    if handle !=nowhandle:
        driver.switch_to.window(nowhandle)
        driver.close()
        driver.switch_to.window(handle)
    # else:
    #     driver.close()
for idcard in values :
    time.sleep(2)
    driver.find_element_by_xpath("//div[@class='menu_dropdown bk_2']/dl/dt/i[@class='Hui-iconfont menu_dropdown-arrow']").click()
    print("打开录入查询菜单。。。。")
    handlenow1=driver.current_window_handle
    print(handlenow1)
    time.sleep(3)
    driver.find_element_by_xpath("//div[@class='menu_dropdown bk_2']/dl/dd/ul/li/a").click()
    print("进入档案管理页面。。。。。。。。")
    handlenow=driver.current_window_handle
    print(handlenow)
    # 切换frame
    frame=driver.find_elements_by_tag_name("iframe")
    driver.switch_to.frame(frame[1])
    time.sleep(2)
    driver.find_element_by_xpath("//div[@id='add']/a").click()
    print("新增档案信息。。。")
    time.sleep(2)
    iframe3=driver.find_element_by_xpath("//iframe[contains(@id,'layui-layer-iframe')]")
    driver.switch_to.frame(iframe3)
    driver.find_element_by_xpath("//input[@id='name']").clear()
    driver.find_element_by_xpath("//input[@id='name']").send_keys(u"尹飞雪")
    driver.find_element_by_id("personcardNo").clear()
    driver.find_element_by_id("personcardNo").send_keys(idcard)
    driver.find_element_by_xpath("//div[@class='j_hform']/p[4]/input").clear()
    driver.find_element_by_xpath("//div[@class='j_hform']/p[4]/input").send_keys("15868686868")
    time.sleep(3)
    driver.find_element_by_id("saveBtn").click()
    # 刷新页面
    driver.refresh()
    print(idcard)

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Java 实现批量更新和保存数据可以使用 JDBC(Java Database Connectivity)来连接数据库并执行 SQL 语句。 这里是一个示例代码,假设你要更新数据库中名为 "users" 的表中的所有记录: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class Main { public static void main(String[] args) throws SQLException { String url = "jdbc:mysql://localhost:3306/mydatabase"; String username = "user"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); String sql = "UPDATE users SET name = ?, email = ? WHERE id = ?"; PreparedStatement statement = connection.prepareStatement(sql); // 设置参数并执行批量更新 statement.setString(1, "Alice"); statement.setString(2, "alice@example.com"); statement.setInt(3, 1); statement.addBatch(); statement.setString(1, "Bob"); statement.setString(2, "bob@example.com"); statement.setInt(3, 2); statement.addBatch(); // 执行批量更新 statement.executeBatch(); // 关闭连接 statement.close(); connection.close(); } } ``` 在这个例子中,我们使用了 `PreparedStatement` 类和它的 `addBatch` 方法来实现批量更新。具体来说,我们可以在同一个 `PreparedStatement` 对象中设置多组参数,然后使用 `addBatch` 方法将它们加入批处理中。最后,我们使用 `executeBatch` 方法来执行批量更新。 注意,这段代码使用的是 MySQL 数据库,所以需要使用 MySQL 的 JDBC 驱动。如果你使用的是其他数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值