Selenium-webdriver Series Python Tutorial (5) ———— how to position frame

Source: Internet
Author: User

In Web UI Automation testing, frame has always been a headache, just as it must be crowded with buses to get to work.

The problem with frame is always stuffy tangled up and dejected.

Frame was also a tricky issue in the past when using SELENIUM1. Not only to be scripted.

A set of settings, and in the actual code writing process will encounter a variety of weird problems. Frame is like

The defence of the Chinese men's soccer is difficult to solve.

Selenium Webdriver handling frame is simpler than some test tools,

Yue.

Take the following HTML code as an example, and we'll look at how to position the elements on the frame.

Frame.html

<title>frame</title>

<body>

<div class= "Row-fluid" >
<div class= "Span10 well" >
<iframe id= "F1" src= "part1. html" width= "
height= "></iframe>
"
</div>
</div>
</body>


Part1.htm

<title>inner</title>

<body>

<div class= "Row-fluid" >
<div class= "Span6 well" >
<iframe id= "F2" src= "http://www.baidu.com" width= "700"
height= "></iframe>
"
</div>
</div>
</body>


The Switch_to method new1 a Targetlocator object, using the object's frame method to identify the current

The "subject" moves to the frame that needs to be positioned.

From selenium import Webdriver

Import Os,time

Objdriver = Webdriver. Chrome ()

#相对路径 (in the same directory as the Python file)

Frame_file = ' file://' + os.getcwd () + '/frame.html '))

Objdriver.get (File_path)

Objdriver.implicitly_wait (30)

#先找到到ifrome1 (id = f1)

Objdriver.switch_to_frame ("F1")

#再找到其下面的ifrome2 (ID =f2)

Objdriver.switch_to_frame ("F2")

#操作f2中的控件

objdriver.find_element_by_id ("kw"). Send_keys ("Selenium")

Time.sleep (5)

Objdriver.quit ()

Webdriver's frame processing style makes people feel that the pain is more and more relaxed, this progress is worth affirming.

Note:

The usage of browser.implicitly_wait () should be more intelligent than time.sleep (), which can only choose a fixed time wait, the former may be in a time range of intelligent waiting.

Driver.switch_to_window () is used in the same way as Switch_to_frame, except that Switch_to_window () is not positioning the nested frame, but rather the positioning of the window.


Selenium-webdriver Series Python Tutorial (5) ———— how to position frame

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.