企业🤖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() ~~~