Selenium-webdriver (Python) (vii) Multi-layer frame or window positioning

Source: Internet
Author: User
Tags min sleep

This section knowledge points:

Positioning of a multi-tier frame or window:

Switch_to_frame ()

Switch_to_window ()

Smart wait:

Implicitly_wait ()

For a modern web application, there are often frames or Windows (window) applications, which poses a challenge to our positioning.

Sometimes we locate an element, the locator is not a problem, but it is not fixed, this time we have to check whether this element is in a frame, Seelnium Webdriver provides a switch_to_frame method, can easily solve this problem.

Frame.html

 

Inner.html

 

Driver.switch_to_window ()

It is possible to nest not the frame, but the window, and the true method of the window: Switch_to_window

Usage is the same as Switch_to_frame:

Driver.switch_to_window ("Windowname")

Implicitly_wait ()

Careful words will find that the above example has browser.implicitly_wait (30), its usage should be more intelligent than time.sleep (), the latter can only choose a fixed time waiting, the former can be in a time range intelligent waiting.

Document Explanation:

Selenium.webdriver.remote.webdriver.implicitly_wait (time_to_wait)

Implicitly waits for an element to be found or a command is completed; This method only needs to be invoked once per session

Time_to_wait: Wait Time

Usage:

Driver.implicitly_wait (30)

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Related Article

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.