Objective
The environment has been set up in the front, which begins with the formal learning of Selenium's webdriver framework. We usually say selenium automation, in fact, it is not similar to QTP and other GUI-like visualization tools, we want to learn is the Webdriver framework of the API.
This article mainly tells how to use Python to invoke the API of the Webdriver framework, to do some general operations on the browser, such as open, forward, backward, refresh, set the window size, screenshot, exit and other operations.
First, open the site
1. First step: Import Webdriver module from selenium
2. Open the Firefox browser (IE and chrome corresponding below)
3. Open Baidu website
Second, set the sleep
1. Since the Baidu Web site opened, the page loading takes a few seconds, so it is best to wait until the page load is complete before continuing the next operation
2. Import the time module, the time module is the python comes with, so no need to download
3. Set the wait time in seconds (s) and the time value can be a decimal or an integer
Third, page refresh
1. Sometimes after the page operation, the data may not be synchronized in time, need to re-refresh
2. Here you can simulate the Refresh page operation, which is equivalent to the Refresh button after the browser input box
Iv. forward and backward
1. When you open two pages in a browser, you want to return to the previous page, which is equivalent to the left arrow button in the upper left corner of the browser
2. After returning to the previous page, you can also switch to the next page, which is equivalent to the right arrow button in the upper left corner of the browser
V. Setting the window size
1. You can set the browser window size, such as setting the window size to phone resolution 540*960
2. You can also maximize the window
Six, screen cutting
1. After you open the Web site, you can also screen screenshots
2. Set the save path after screenshot + file name + suffix
Vii. exit
1. There are two ways to exit, one is close; the other is quit.
2.close is used to close the current window, and when more windows are open, you can close some windows with close
3.quit to end a process, close all windows
4. End the test with quit. Quit can reclaim temporary files from C drive
Master the basic operation of the browser, then you can begin to learn the element positioning, element positioning needs to have a certain HTML basis. There is no basis can press the browser F12 shortcut first look at the layout of HTML, first understand some of it.
Selenium2+python Automation 5-basic method of Operation browser