Content reference to: Official API documentation, download link: http://download.csdn.net/detail/kwgkwg001/4004500
Bug Master: "SELENIUM2 Automation Test Practice-based on Python language"
First, the principle of webdriver
1, about Webdriver
Design mode: According to the classic design mode of server-client design;
Server side: Remote server, which can be any browser, when the script launches the browser, the browser is remote server, its role is to wait for the client to send a request and respond;
Client side: In a nutshell, our test code, some of the behavior in the test code is sent to the test browser--remote server,remote Server to accept the request as an HTTP request, to perform the appropriate action,
and returns the execution status, return value and other information in response;
2. Webdriver Work Flow
①webdriver launches the target browser and binds to the specified port, and the launched browser instance will act as the remote Server for Webdriver;
The ②client end sends HttpRequest to the remote server's listening port via Commandexcuter (Communication protocol: the Webdriver Wire protocol);
③remote server needs to rely on native browser components (for example: Chromedriver.exe) to convert the browser's native calls;
3, WebDriver.log
Python provides the logging module to the running application, providing a standard information output interface. It provides a definition of the Basicconfig method for basic information, opens the Debug module,
You can capture a client-side request sent to the server, as in the following example:
# import logging module to capture requests sent by client
# Coding=utf-8
From selenium import Webdriver
Import logging
Logging.basicconfig (level=logging. DEBUG)
Driver = Webdriver.chrome ("F:\ Installation Tool \python\chromedriver.exe")
Driver.get ("www.baidu.com")
driver.find_element_by_id ("kw"). Send_keys ("Selenium")
driver.find_element_by_id ("su"). Click ()
Driver.quit ()
Second, webdriver positioning method
Webdriver is a set of APIs based on the selenium design of the operating browser that implements this set of APIs for a variety of programming languages, and in the Python perspective, Webdriver is a third-party library of Python that implements Web automation.
1, Webdriver positioning method
The Webdriver localization method provides eight methods for locating elements, and the corresponding methods and properties are as follows:
2. Comparison of similar functions between XPath and CSS
3. Use by to locate the element
For the 8 positioning methods described previously, Webdriver also provides an alternative approach, which is to call the Find_element () method uniformly, declare the positioning method by using by, and pass in the positional parameters of the corresponding positioning method, as shown in the following example:
The Find.element () method is only used to locate the element, it requires two parameters, the first parameter is the type of the positioning, provided by the by, the second parameter is the specific way to locate, before using the by class to import;
# Importing Packages by class
From selenium.webdriver.common.by Import by
Find.element (by.id, "kw")
Find.element (By.name, "WD")
Find.element (By.class_name, "S_ipt")
Find.element (by.tag_name, "input")
Find.element (By.link_text, "News")
Find.element (By.partial_link_text, "new")
Find.element (By.xpath, "//*[@class = ' bg s_btn '")
Find.element (By.css_selector, "span.bg s_btn_wr>input#su")
PS: The above example is taken from the front-end elements of Baidu homepage, extended reading can refer to the following links:
Test Tutorial Web: http://www.testclass.net/selenium_python/
Python+selenium Category: http://www.cnblogs.com/AlwinXu/tag/Python/
About UI Automation, recommend the system to learn the basics of the front-end related, you can go to the network to see ...
(iii) Webdriver API (UP)