ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 循环添加用户 循环添加3个用户 只需输入用户名、电子邮件、用户角色随机选择 ~~~ #coding=utf-8 # @Author: SamWang # @Date: 2019-11-15 15:30:48 # @Last Modified time: 2019-11-15 16:03:28 from selenium import webdriver from time import sleep,time from selenium.webdriver.support.ui import Select from random import randint d = webdriver.Chrome() d.get('http://os-201804081018/blog/wp-login.php') d.maximize_window() sleep(1) # 登录系统 d.find_element_by_css_selector('#user_login').send_keys('test') sleep(1) d.find_element_by_css_selector('input[type="password"]').send_keys('test123') sleep(1) d.find_element_by_css_selector('p.submit input#wp-submit').click() sleep(1) d.find_element_by_css_selector('#menu-users .wp-menu-name').click() for i in range(10): username = 'br{0}'.format(int(time())) # 点击添加用户 d.find_element_by_css_selector('.page-title-action').click() sleep(0.5) d.find_element_by_css_selector('#user_login').send_keys(username) sleep(0.5) d.find_element_by_css_selector('#email').send_keys('{0}@qq.com'.format(username)) sleep(0.5) # 下拉框定位 ele = d.find_element_by_css_selector('#role') # 定位到所有的下拉框选项 all_option=d.find_elements_by_css_selector('#role option') # 获取下拉框选项的个数 lenth = len(all_option) # 生成一个随机数 index = randint(0,lenth-1) Select(ele).select_by_index(index) d.find_element_by_css_selector('#createusersub').click() ~~~