Selenum Threding Multithreaded Running instance

Source: Internet
Author: User

1. Configure related drivers

Chrome Driver

Download driver, configure to environment variable

such as Xxxxchrome.jar to create a new directory c:/driver---Configure the directory to an environment variable

Firefox driver

Download the driver, unzip the Geckodriver-v0.21.0-win64.zip, drag the Geckodriver-v0.21.0-win64 to the Python--script directory

IE driver

Download the driver and IEDriverServer.exe it to C:\Windows\System32

2. Code

From selenium import Webdriver
From threading Import Thread
Import Threading,time
From time import CTime

def test_baidu (Browser,search):
Print (' start:%s '% CTime ())
Print (' broswer:%s '%browser)
If browser== ' IE ':
Driver=webdriver. Ie ()
Print (' IE search results ')
Elif browser== ' Chrome ':
Driver=webdriver. Chrome ()
Print (' Google search results ')
elif browser== ' FF ':
Driver=webdriver. Firefox ()
Print (' Firefox search results ')
Else
Print (' browser error ')
Driver.get (' http://www.baidu.com ')
driver.find_element_by_id (' kw '). Send_keys (search)
driver.find_element_by_id (' su '). Click ()
Time.sleep (1)
Driver.quit ()
If __name__== ' __main__ ':
#指定浏览器搜索内容
lists={' Chrome ': ' Threading ', ' IE ': ' Start ', ' ff ': ' Fight '}
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 ())

Selenum Threding Multithreaded Running instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.