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