Selenium2+python Automation 5-basic method of Operation browser

Source: Internet
Author: User

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

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.