Selenium positioning HTML Elements (Python)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.