Selenium2+python Automation 1-Operation Browser

Source: Internet
Author: User

With the development of the test industry, now whether in the search for work or in the actual work, the need to master automation is more and more common, here to record some of the knowledge of the entry, hope that the reader can have some help! Good da, get to the point, this article mainly records how to use Python to invoke the API of the Webdriver framework, do some regular 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 the Webdriver module from the selenium.

2. To open the Firefox browser (Chrome and IE corresponding to the following)

3. Open Baidu website

Here is a sentence to write when you pay attention to the post-Firefox brackets!!!

Second, set the sleep

1. Since opening the Baidu Web site, the page loading takes a few minutes, so it is best to wait until the page load is complete before proceeding to the next step.

2. Import the time module, which is Python-free, so no download is required.

3. Set the wait time in seconds (s) and the time value can be a decimal or an integer.

Hey, here again, sometimes write script debugging, there are errors, prompted a lot of wrong reasons and see not quite understand, if you feel that the element is not loaded out of the problem, you can add a time to wait to try.

Third, page refresh

1. Sometimes after the page operation, the data may not be synchronized in time and need to be refreshed again.

2. 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 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 of exiting, one is close and the other is quit.

2.close is used to close the current window, and when the window is open, you can close some windows with close.

3.quit is used to end the process and close all windows.

4. Finally end the test, the quit,quit can be used to recover the temporary files in the C disk.

Master the basic operation of the browser, you can begin to learn the positioning of elements, not to be continued ...

Selenium2+python Automation 1-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.