# -*- coding: utf-8 -*-
# @Time : 2019/1/3 10:03
# @Author : Philly
# @File : multi_login.py
# @Description: 多用户并发登录
from selenium import webdriver
import threading
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains
import random
from selenium.webdriver.common.keys import Keys
def login(user_name, password, barcode):
# 设置chromedriver具体访问地址
chromedriver = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
# browser = webdriver.Chrome(executable_path=chromedriver)
browser = webdriver.Chrome(executable_path=chromedriver)
# 设置浏览器窗口最大化
browser.maximize_window()
# 谷歌浏览器访问物流地址
browser.get(‘http://khlis.yktest.com/logistics/home‘)
sleep(2)
browser.find_element_by_id(‘user_name‘).send_keys(user_name)
browser.find_element_by_id(‘password‘).send_keys(password)
browser.find_element_by_id(‘editBtn‘).click()
sleep(3)
print(user_name + ‘登录了‘)
ml = browser.find_element_by_xpath(‘//*[@id="site-menu"]/div[1]‘)
ActionChains(browser).move_to_element(ml).perform()
sleep(2)
gl = browser.find_element_by_xpath(‘//*[@id="site-menu"]/div[2]/ul/li[1]/span‘)
ActionChains(browser).double_click(gl).perform()
sleep(1)
lr = browser.find_element_by_link_text(‘标本录入‘).click()
sleep(3)
pp = browser.find_element_by_xpath(‘//*[@id="sitt"]/div[1]/div[3]/ul‘)
ActionChains(browser).move_to_element(pp).perform()
browser.find_element_by_id(‘siadd‘).send_keys(Keys.F8)
browser.find_element_by_id(‘barcode‘).send_keys(barcode)
yy = browser.find_element_by_id(‘comboText3‘)
yy.clear()
yy.send_keys(‘医院‘)
sleep(1)
yy.send_keys(Keys.ENTER)
browser.find_element_by_id(‘subject_name‘).send_keys(‘xingming‘)
xb = browser.find_element_by_xpath(‘//*[@id="form1"]/div[1]/div/div[1]/div/div[1]/div[5]/div[2]/span/input[1]‘)
xb.send_keys(‘男‘)
xb.send_keys(Keys.SPACE)
sleep(1)
xb.send_keys(Keys.ENTER)
sleep(1)
browser.find_element_by_xpath(‘//*[@id="form1"]/div[1]/div/div[1]/div/div[1]/div[6]/div[2]/span/input[1]‘).send_keys(‘32‘)
xm = browser.find_element_by_id(‘comboText10‘)
xm.clear()
xm.send_keys(‘离子‘)
sleep(1)
xm.send_keys(Keys.ENTER)
sleep(1)
browser.find_element_by_id(‘sisave‘).click()
if __name__ == ‘__main__‘:
user_barcode = {
‘gl01‘: ‘201901038600‘,
‘wl001‘: ‘201901038300‘,
‘wl002‘: ‘201901038200‘
}
threads = [] # 定义一个线程池
for thr in user_barcode.keys():
th1 = threading.Thread(target=login, args=(thr, ‘123abc‘, user_barcode[thr])) # 创建线程
threads.append(th1)
# th2 = threading.Thread(target=login, args=(‘wl001‘, ‘123abc‘))
# threads.append(th2)
for th in threads:
th.start() # 启动线程
th.join() # 等待线程执行完成
print(‘all have end.‘)
原文地址:https://www.cnblogs.com/liuliu3/p/10214522.html
时间: 2024-10-28 23:19:01