I. Installing Python
1. Configure the environment variable c:\python27;c:\python27\scripts
2. Verify that the Pyton is available and enter Python in cmd without error.
Two. Installing the Selenium Library
4. Install selenium; in cmd, enter: Pip install Selenium
Three. The positioning methods corresponding to the Webdriver are:
- Driver.find_element_by_name ()--most commonly used, simple
- DRIVER.FIND_ELEMENT_BY_ID ()--most commonly used, simple
- Driver.find_element_by_link_text ()--positioning text connection is useful
- Driver.find_element_by_xpath ()--the most flexible, versatile
- Driver.find_element_by_css_selector ()
Four. Friebug
1. Open the Firebug plugin of Firefox browser, click the mouse arrow in the top left corner of the plugin, then click on the element on the page, the HTML tab of the Firebug plugin will see the page code, the mouse moves to the element's label click. For example, we click on the Baidu home page "Baidu click" button:
From Firepath, you can see properties such as the Id,tag,class of the element.
- Chrome developer Tools (F12)
Open the Chrome browser and press F12 on the keyboard to open the developer tools. You can get the same results as Firepath from the developer tools:
ID and name Locator
This is a simple and efficient method. For example, the method of positioning Baidu Home text box, we can use the ID to locate (the element provides an id attribute, you can uniquely navigate to it):
To locate the "settings" link in the top right corner of the Baidu home page, we can use name to locate (the element provides the Name property and can uniquely navigate to it):
by Linx text location:
XPath positioning
CSS Positioning
Python+selenium positioning elements