This article is not to introduce a variety of methods (ID, name, tag_name, CSS, XPath, etc.) to locate HTML elements of the popularity of the article, the network of various documents and blogs are more comprehensive introduction. This is just a matter of keeping track of the individual problems and solutions that are encountered in your own practice.
Recommended Selenium Official document (Python version): http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
You can search for keywords to get function usage and source code.
The following records the problems and workarounds that are encountered in locating HTML elements (continuous updates).
1. Frame Positioning without ID
Problem Description: The element inside the frame needs to be positioned, but this frame has no ID.
Workaround: The Swich_to_frame () function is defined as follows:
1 defswitch_to_frame (Self, frame_reference):2 """3 switches focus to the specified frame, by index, name, or webelement.4 5 : Args:6 -frame_reference:the name of the window to switch to, an integer representing the index,7 or a webelement is a (i) frame to switch to.8 9 : Usage:Ten driver.switch_to_frame (' frame_name ') One driver.switch_to_frame (1) A Driver.switch_to_frame (Driver.find_elements_by_tag_name ("iframe") [0]) - """ -Self.execute (Command.switch_to_frame, {'ID': Frame_reference})
There are 3 forms of parameter frame_reference. For a frame without ID, you can navigate to the frame with the following 2 parameters. In contrast, the last 2 parameters are more like the "relative position" of all the frames in a page to locate a particular frame, while the 1th parameter is positioned by an absolute "name".
Selenium positioning HTML Elements (Python)