Python + selenium automated testing of the five - Browser Basic Operation

Foreword

Previous four articles have introduced environment to build the basic processes and operations, let's start learning selenium test, this paper explains webdriber framework. Selenium is like real users do the same, Selenium tests can Internet Explorer on Windows, Linux and Macintosh, Chrome and Firefox run. Of course, if you can use for visualization of selenium IDE plug-in browser, it is a browser plug-in that case each browser plug-in is added.

         The following mainly explains how to use python to call API webdriver framework, as well as how to control the operation of the browser.

 

First, start the browser and go to a web site

         1. Start Pycharm and engineering to create, import the module webdriver

         2. Start browser to Firefox browser, for example

         3. Access Baidu HTTP: // www.baidu.com

 

Second, setting the sleep or wait longer

1. Access web site page load takes time, so it is best to wait a few seconds after initiating access, wait for the page to finish loading, and then operate on the page

2. Set the wait time module needs time, time is a Python module that comes with no downloads cited "directly in the program Import time ."

3.time is in seconds (s), the fractional time value may be an integer or may be

 

Third, the page refreshes

1. The first step in accessing a Web page, the second step wait for 5 seconds, but it is possible for various reasons did not load a page, this time you need to refresh the page

2. Analog refresh the page "driver.refresh ()"

Fourth, forward and back (return to the previous step)

1. continuous access to two web browser, want to return to the previous page, the equivalent of the upper left corner of the browser left arrow button

2. After returning to the previous page, or switch to the next, corresponding to the top left and right arrow buttons browser

Fifth, the browser window size

1. Start your browser, you can control access to the browser window size: the largest, custom

2. Do not set the default window size

 

Six screenshots

Sometimes we need to save the page to access most of the data will need follow-up tests to intercept screen, set up to develop the screenshot save path + file name + suffix

Seven, exit

1. Exit There are two ways, one is Close; another is quit

2. "driver.close ()" when more window, closing the current window, a window, close the browser

3. "driver. Quit ()" for the end of the process, close all windows

4. Finally the end of the test, use quit. Temporary files can be recovered quit the c drive

The above describes the basic operation of the command browser, the following exercises will enter a page element positioning, positioning elements need to have some basic html. You can search to see the basics of HTML on the Web.

Recognition under Fanger Wei code or micro-channel public number search "test micro-service", concerned me more about the test information and technology.

https://mmbiz.qpic.cn/mmbiz_png/POknAFpxeiblh66FmgsTnicyMIBRalFwzX5sm4B8KUC8rvF3kVymkF1XibRAdzCHpPeebFqbKeIbxX02iaCezgqMzw/640?wx_fmt=png

 

Published 17 original articles · won praise 2 · Views 5269

Guess you like

Origin blog.csdn.net/tiekun888/article/details/104927747