通过不同的浏览器来启动不同的线程.py
from threading import Threadfrom selenium import webdriverfrom time import ctime,sleep#测试用例def test_baidu(browser,search): print("start:%s" % ctime()) print("browser:%s" % browser) if browser == "ie": driver = webdriver.Ie() elif browser == "chrome": driver = webdriver.Chrome() elif browser == "ff": driver = webdriver.Firefox() else: print("browser参数有误,只能为ie、ff、chrome") driver.get("http://www.baidu.com") driver.find_element_by_id("kw").send_keys(search) driver.find_element_by_id("su").click() sleep(2) driver.quit()if __name__ == ‘__main__‘: #启动参数: lists = {"chrome":"threading","ie":"webdriver","ff":"python"} threads = [] files = range(len(lists)) #创建线程 for browser,search in lists.items(): t = Thread(target=test_baidu,args=(browser,search)) threads.append(t) #启动线程 for t in files: threads[t].start() for t in files: threads[t].join() print("end:%s" % ctime())
相关推荐
xiangxiaojun 2020-09-23
letheashura 2020-08-14
王练 2020-07-18
xiangxiaojun 2020-06-25
Feastaw 2020-06-18
ELEMENTS爱乐冬雨 2020-06-14
jjddrushi 2020-06-14
云之高水之远 2020-06-14
chongtianfeiyu 2020-06-12
Reiki 2020-06-12
songerxing 2020-06-11
王练 2020-06-11
tiankele0 2020-06-09
dangai00 2020-06-06
云之高水之远 2020-06-05
curiousL 2020-06-01