SELENIUM3 Python3 Web Automation testing from the ground up to the actual project of the two different settings of the browser

Source: Internet
Author: User

In the previous chapter we learned how to initialize our driver through Webdriver, and then we just need to be able to do our automation through driver, first we know we need to know that when we have driver, all we have to do is to operate our browser, When we open the default is a medium window browser, if you open and need to go to the entire window to maximize, we only need to pass the following method:

Driver.maximize_window ()

This method can be used to maximize the browser, of course, this is the current driver browser, regardless of whether you initialize the Chrome browser or Firefox can be anything, of course, the maximization has minimized, we only need to pass:

Driver.minimize_window ()

Some people will question, say there is the biggest, also have the smallest, then I can not be able to set their own size, rather than two extreme? The answer is yes, and we just need to do it the following way:

Driver.set_window_size ()

Some people see this confusion, do not know how to use? In fact, we can look at these methods to tune out after the following are some explanations, see:

In the above picture, we can see that the method gives the hint that the set method requires three parameters, but there is a parameter has a default parameter, so we only need to pass the width, height of these two parameters on the line, so the name think, these two parameters is our browser window width and height.

When we set the browser to be wide, high then the browser window to the basic operation we basically mastered, but this is not enough, we still have a lot of needs, such as we may have a bad network in the current page, open the page has been blank, this time we need to refresh try to re-operation, then how to do? We just need to go through the following methods:

Driver.refresh ()

Some people see this feel to realize the refresh, but do not know how to mean, then we look at the source:

Then the above source parsing we see, in fact, he said to tell you to refresh the current page, the use of what method, then we know.

When we open the browser, refresh, and set the size of the initialization after the completion of the common operation is basically done, but there are some business need to pay attention to the problem, say, such as in the current window click a link, and then jump to another page, Do we need to go back to the original page when we finish the page or validate the page element? This time we can use:

Driver.back ()

This method to complete, this method is mainly to complete the back browser, it is equivalent to the top left corner of the browser to return the button, return to the previous action page. Now that there is a return, there is progress:

Driver.forward ()

At this point we will basically complete the browser operation, then a complete base code is as follows:

#coding =utf-8from Selenium Import webdriverdriver = Webdriver. Chrome () driver.get (' http://www.baidu.com ') Driver.maximize_window () Driver.minimize_window () Driver.set_window_ Size (' + ', ' Max ') Driver.refresh () Driver.back () Driver.forward ()

It is easy to see the above discovery, which is the use of some basic APIs.

SELENIUM3 Python3 Web Automation testing from the ground up to the actual project of the two different settings of the 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.