Essays and records to facilitate their access to fellow travelers.
#------------------------------------------------I ------------------------------------------- dividing line is a shame
Learning before selenium automation, it is best to learn HTML, CSS, JavaScript and other knowledge, help to understand the principles of operation and positioning elements. About python and selenium install their own search for other information,
Here do not introduced, all examples use python3.6 + selenium execution.
WebDriver mainly provided is a method of operation of the various elements of the page, but he also provides some method of operating a browser, such as control of the browser size, operating the browser forward and back and so on.
#------------------------------------------------I ------------------------------------------- dividing line is a shame
Control the browser Back, Forward
When using a browser to browse web pages, the browser provides the back and forward buttons to switch between pages can conveniently be viewed, the WebDriver also provides a corresponding back () and forward () method to simulate back and forward buttons. Below to demonstrate the use of these two methods by way of example.
# Import webdriver module which is used to control the browser from Selenium Import webdriver Import Time Driver = webdriver.Chrome () # instantiated, and opened to specify the Firefox browser # access Baidu Home first_URL = " http://www.baidu .com " driver.get (first_URL) # Print ( " now access% S " % first_URL) the time.sleep ( 1 ) # access news page second_URL = " http://news.baidu.com " Print ( " now access% S " %second_URL) driver.get (second_URL) the time.sleep ( 1 ) # return (back) to the Baidu home page print ( " the Back to% S " % first_URL) driver.back () the time.sleep ( 1 ) # forward to the news page print ( " Forward to% S " % second_URL) driver.forward ()
The results show:
The first step to open the Baidu home page, news page Baidu open the second step, third step is to use back method returns the Baidu home page, the fourth step using forward method proceeds to the news page, the equivalent of the browser forward and back buttons.