#!/usr/bin/python
#-*-Coding:utf-8-*-
__author__ = ' Zuoanvip '
#在测试过程中经常遇到frame嵌套的应用, the Join page has a, b two frame,b within a, then to find the elements in B, you should first find a and then to B. Can be done by switch_to_frame
From selenium import Webdriver
Import OS
#打开页面
Driver = Webdriver. Firefox ()
File_path = ' file:///' + os.path.abspath (' frame.heml ')
Driver.get (File_path)
#等待30s
Driver.implicitly_wait (30)
#先找到id =f1 's Frame
Driver.switch_to_frame (' F1 ')
#再找到id =f2 's Frame
Driver.switch_to_frame (' F2 ')
#接下来定位frame2里面的元素
driver.find_element_by_id (' kw '). Send_keys (' Selenium ')
driver.find_element_by_id (' su '). Click ()
==========================================================================================
Frame's Source code:
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title>frame</title>
<script type= "Text/javascript" async= "
"Src=" ></script> "Http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
<link href= "Http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css"
rel= "stylesheet"/>
<script type= "Text/javascript" >$ (document). Ready (function () {
});
</script>
<body>
<div class= "Row-fluid" >
<div class= "Span10 well" >
<iframe id= "F1" src= "inner.html" width= "" "Height=" ></iframe>
</div>
</div>
</body>
<script src= "Http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js" ></script>
---------------------------------------
Source code for inner:
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title>inner</title>
<body>
<div class= "Row-fluid" >
<div class= "Span6 well" >
<iframe id= "F2" src= "http://www.baidu.com" width= "" "height=" >
</iframe>
</div>
</div>
</body>
Selenium Python (eight) positioning objects in a frame