Selenium Python (eight) positioning objects in a frame

Source: Internet
Author: User

#!/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

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.