Locating a group of objects
Locate a group of objects--find_elements_by_ ... (), note, here is elements, plural. The returned result is a list of values that we need to use to get the elements we want. There is so much to be aware of. See a piece of code immediately understand:
This is Baidu in the upper right corner of a few tags. We see that the class from "News" to "academic" is the same:
# coding: utf-8
from selenium import webdriverdriver = webdriver.Firefox()driver.get("http://www.baidu.com")driver.maximize_window()
grou = driver.find_elements_by_class_name("mnav")
# 查看该组对象的长度
print len(grou)
# 点击新闻按钮
driver.find_elements_by_class_name("mnav")[0].click()
The above is to locate a set of elements, and then remove the first element, if you click on "Map" on [2].click (). This is the basic knowledge of Python.
Originally also want to continue to say IFRAME positioning, but think there is still more special, take out alone better, so today said so much.
Public search "automated test Practice" or scan the QR code below to add attention ~ ~ ~
"Selenium2 Python Automation Test" (7)--positioning a group of objects