工作中,经常要给多个用户创建账号,为了减少工作量,写了个自动化脚本来帮助我批量创建用户
代码如下:
"""自动创建Jira的学生账号"""from selenium import webdriverfrom time import sleepimport csvdriver = webdriver.Chrome(r'D:\selenium\tools\chromedriver.exe')driver.get("http://xxx:8090/login.jsp") #jira的网址data_set = r'C:\Users\xxx\Desktop\data.csv'sleep(10)#输入用户名和密码driver.find_element_by_id('login-form-username').send_keys('songqin')driver.find_element_by_id('login-form-password').send_keys('woaisongqin')driver.find_element_by_id('login-form-submit').click()sleep(5)driver.find_element_by_id('admin_menu').click()driver.find_element_by_id('admin_users_menu').click()driver.find_element_by_id('login-form-authenticatePassword').send_keys('woaisongqin')driver.find_element_by_id('login-form-submit').click()driver.implicitly_wait(15)#创建用户# driver.find_element_by_id('create_user').click()#创建用户面板reader = csv.reader(open(data_set,encoding='utf-8'))rows = [row for row in reader]print(rows)for i in rows: driver.implicitly_wait(15) driver.find_element_by_id('create_user').click() driver.find_element_by_id('user-create-username').send_keys(i[0]) driver.find_element_by_id('user-create-password').send_keys(i[1]) driver.find_element_by_id('user-create-confirm').send_keys(i[2]) driver.find_element_by_id('user-create-fullname').send_keys(i[3]) driver.find_element_by_id('user-create-email').send_keys(i[4]) driver.find_element_by_id('user-create-submit').click() sleep(2) driver.back()driver.close()
data.csv表格内容:
显示结果: