Selenium lets you automate web browsers. Selenium is a Python module. Apart from the Python module you need a web driver.

From Python you can control Firefox, Chrome, Internet Explorer, Edge and many other browsers. You can open a new url, click buttons and much more.

Related course:

web browsers

selenium browsers

The selenium browsers code below starts several web browsers. They open a website and then close the browser. The web drivers must be installed for this to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#-*- coding:utf-8 -*-
from selenium import webdriver
import time
from tomorrow import threads

def startBrowser(name):
"""
browsers,"firefox"、"chrome"、"ie"、"phantomjs"
"""
try:
if name == "firefox" or name == "Firefox" or name == "ff":
print("start browser name :Firefox")
driver = webdriver.Firefox()
return driver
elif name == "chrome" or name == "Chrome":
print("start browser name :Chrome")
driver = webdriver.Chrome()
return driver
elif name == "ie" or name == "Ie":
print("start browser name :Ie")
driver = webdriver.Ie()
return driver
elif name == "phantomjs" or name == "Phantomjs":
print("start browser name :phantomjs")
driver = webdriver.PhantomJS()
return driver
else:
print("Not found this browser,You can use ‘firefox‘, ‘chrome‘, ‘ie‘ or ‘phantomjs‘")
except Exception as msg:
print("message: %s" % str(msg))

@threads(5)
def run_case(name):
driver = startBrowser(name)
driver.get("https://news.ycombinator.com/")
time.sleep(3)
print(driver.title)
driver.close()
driver.quit()

if __name__ == "__main__":
names = ["chrome", "ff", "ie"]
for i in names:
run_case(i)

selenium browsers

If you are new to selenium, then I highly recommend this book.

Download examples