#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'zuoanvip'
#在测试过程中经常遇到frame嵌套的应用,加入页面上有A、B两个frame,B在A内,那么要找到B中的元素,则首先应找到A然后再到B。可以通过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的frame
driver.switch_to_frame('f1')

#再找到id=f2的frame
driver.switch_to_frame('f2')

#接下来定位frame2里面的元素
driver.find_element_by_id('kw').send_keys('selenium')
driver.find_element_by_id('su').click()

==========================================================================================

frame的源代码:

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>frame</title>
<script type="text/javascript" async="
"src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<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>
</head>
<body>
<div class="row-fluid">
<div class="span10 well">
<h3>frame</h3>
<iframe id="f1" src="inner.html" width="800" height="600"></iframe>
</div>
</div>
</body>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</html>

---------------------------------------

inner的源代码:

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>inner</title>
</head>
<body>
<div class="row-fluid">
<div class="span6 well">
<h3>inner</h3>
<iframe id="f2" src="http://www.baidu.com" width="700" height="400">
</iframe>
</div>
</div>
</body>
</html>

selenium python (八)定位frame中的对象的更多相关文章

  1. 转:python webdriver API 之定位 frame 中的对象

    在 web 应用中经常会出现 frame 嵌套的应用,假设页面上有 A.B 两个 frame,其中 B 在 A 内,那么定位 B 中的内容则需要先到 A,然后再到 B.switch_to_frame  ...

  2. 定位frame 中的对象

    在web 应用中经常会出现frame 嵌套的应用,假设页面上有A.B 两个frame,其中B 在A 内,那么定位B 中的内容则需要先到A,然后再到B.switch_to_frame 方法可以把当前定位 ...

  3. python selenium-webdriver 定位frame中的元素 (十三)

    定位元素时经常会出现定位不到元素,这时候我们需要观察标签的上下文,一般情况下这些定位不到的元素存放在了frame或者放到窗口了,只要我们切入进去就可以很容易定位到元素. 处理frame时主要使用到sw ...

  4. 【虫师讲Selenium+Python】第三讲:操作测试对象

    一.首先呢,选择一个编辑器,我们这里选择的是Sublime Text >Ctrl+B为运行当前脚本的快捷方式 二.编写代码 #coding==utf-8 from selenium import ...

  5. selenium自动化测试入门 定位frame和iframe中的元素对象

    < frame> <iframe> 标签,浏览器会在标签中打开一个特定的页面窗口(框架),它在本窗口中嵌套进入一个网页,当用selenium定位页面元素的时候会遇到定位不到fr ...

  6. selenium+python编写自动化脚本时,定位frame中对象操作

    在web应用中经常会出现frame嵌套的应用,假设页面上有A,B两个frame,其中B在A内,那么定位B中的内容则需要先到A,再到B.switchTo().frame方法可以把当前定位的主题切换到fr ...

  7. Python+Selenium学习--定位iframe中的对象

    场景 在web 应用中经常会出现frame 嵌套的应用,假设页面上有A.B 两个frame,其中B 在A 内,那么定位B 中的内容则需要先到A,然后再到B.      switch_to_frame ...

  8. Python+Selenium 自动化实现实例-定位frame中的元素

    场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如何理解这 ...

  9. Python脚本控制的WebDriver 常用操作 <二十四> 定位frame中的元素

    测试用例场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如 ...

随机推荐

  1. 【原创】【Android New Features】—— 关于ADT 17的BuildConfig.DEBUG

          在日常开发中,我们使用android.util.Log来打印日志,方便我们的开发调试.但是在打包发布时,需要手工把Log关闭,多少会有些不便,而且不排除打包者忘记关闭Log的情况.那么有没 ...

  2. 296. Best Meeting Point

    题目: A group of two or more people wants to meet and minimize the total travel distance. You are give ...

  3. python 细枝末节

    1. print  自动换行 看区别 >>> for i in range(4): ... print i ... 0 1 2 3 >>> for i in ran ...

  4. eclipse安装Gradle

    第一步:下载Gradle>http://gradle.org/gradle-download 第二步:解压gradle-2.5, 配置环境变量:GRADLE_HOME path添加;%GRADL ...

  5. z-index无效问题的解决方法

    在使用z-index这个属性之前,我们必须先了解使用z-index的必要条件: 1.要想给元素设置z-index样式,必须先让它变成定位元素,说的明白一点,就是要给元素设置一个postion:rela ...

  6. Initialization and Class loading - Java

    可以说,类的代码在初次使用时才加载.这通常指加载发生于创建类的第一个对象之时,但当访问 static域或static方法时,也会发生加载(通过下面的这段代码验证). class LoadTest { ...

  7. Test Tools

    1. http://www.dummytextgenerator.com/: Generate dummy text 2. fsutil file createnew D:\New.txt 1024: ...

  8. zabbix接口调用注意事项--Python

    不知道该怎么写,但是明显得写点什么,担心时间长了,忘记,再回顾时又要重新摸索一遍 一.Request:post params: 1. 第一层的参数处理: 第一层的参数设置为变量 2. 其他层参数格式不 ...

  9. POJ -3190 Stall Reservations (贪心+优先队列)

    http://poj.org/problem?id=3190 有n头挑剔的奶牛,只会在一个精确时间挤奶,而一头奶牛需要占用一个畜栏,并且不会和其他奶牛分享,每头奶牛都会有一个开始时间和结束时间,问至少 ...

  10. HeadFirst Jsp 05 (属性和监听)

    活用DD, 比如, 我想设置一个email地址, 但是不像在servlet中硬编码, 如果能再web.xml中设置一个参数, 直接拿到这个参数就更好一点. 容器建立一个servlet时, 它会读DD( ...