selenium python (八)定位frame中的对象
#!/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中的对象的更多相关文章
- 转:python webdriver API 之定位 frame 中的对象
在 web 应用中经常会出现 frame 嵌套的应用,假设页面上有 A.B 两个 frame,其中 B 在 A 内,那么定位 B 中的内容则需要先到 A,然后再到 B.switch_to_frame ...
- 定位frame 中的对象
在web 应用中经常会出现frame 嵌套的应用,假设页面上有A.B 两个frame,其中B 在A 内,那么定位B 中的内容则需要先到A,然后再到B.switch_to_frame 方法可以把当前定位 ...
- python selenium-webdriver 定位frame中的元素 (十三)
定位元素时经常会出现定位不到元素,这时候我们需要观察标签的上下文,一般情况下这些定位不到的元素存放在了frame或者放到窗口了,只要我们切入进去就可以很容易定位到元素. 处理frame时主要使用到sw ...
- 【虫师讲Selenium+Python】第三讲:操作测试对象
一.首先呢,选择一个编辑器,我们这里选择的是Sublime Text >Ctrl+B为运行当前脚本的快捷方式 二.编写代码 #coding==utf-8 from selenium import ...
- selenium自动化测试入门 定位frame和iframe中的元素对象
< frame> <iframe> 标签,浏览器会在标签中打开一个特定的页面窗口(框架),它在本窗口中嵌套进入一个网页,当用selenium定位页面元素的时候会遇到定位不到fr ...
- selenium+python编写自动化脚本时,定位frame中对象操作
在web应用中经常会出现frame嵌套的应用,假设页面上有A,B两个frame,其中B在A内,那么定位B中的内容则需要先到A,再到B.switchTo().frame方法可以把当前定位的主题切换到fr ...
- Python+Selenium学习--定位iframe中的对象
场景 在web 应用中经常会出现frame 嵌套的应用,假设页面上有A.B 两个frame,其中B 在A 内,那么定位B 中的内容则需要先到A,然后再到B. switch_to_frame ...
- Python+Selenium 自动化实现实例-定位frame中的元素
场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如何理解这 ...
- Python脚本控制的WebDriver 常用操作 <二十四> 定位frame中的元素
测试用例场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如 ...
随机推荐
- Hibernate笔记——第一个简单实例
1. 首先进行框架配置 导包 hibernate配置xml文件 ======================= 2. 创建并配置POJO类 Hibernate是操作持久化层的框架,和数据库打交道,其 ...
- IDL---ENVI
ENVI;启动envi file=envi_pickfile();选择文件dialog,返回值就为file ENVI_OPEN_FIle,file,r_fid=fid;根据文件名打开file,并且返回 ...
- google 访问
http://maolihui.com/goagent-detail.htmlgoagent教程详细版https://aiguge.xyz/chrome-goagent-proxy-switchyom ...
- 【公司要求】- RPC学习(一)
HADOOP-IPC(这里说的是1.0.4版本) 是轻量级RPC,在hadoop中主要用于2方面 1.TaskTracker和JobTracker 通讯. 2.NameNode和DataNode通讯. ...
- 【图像算法】七种常见阈值分割代码(Otsu、最大熵、迭代法、自适应阀值、手动、迭代法、基本全局阈值法)
图像算法:图像阈值分割 SkySeraph Dec 21st 2010 HQU Email:zgzhaobo@gmail.com QQ:452728574 Latest Modified Da ...
- 如何写计算机会议的rebuttal
其实最好的教材就是实例,恰好NIPS会议会把往年所有论文的Rebuttal都贴出来...,见这里:http://papers.nips.cc/ 同时,圈内同行也总结了不少经验,下面转帖其他人的经验 = ...
- hdoj - 5202 Rikka with string (BestCoder Round #37 ($))
http://acm.hdu.edu.cn/showproblem.php?pid=5202 字符串处理的题,要细心. 给定一个只包含小写字母和问号的字符串,让我们还原出本来的字符串,把问号替换成任意 ...
- C语言输出当前日期和时间
#include <stdio.h> #include <time.h> char* asctime2(const struct tm *timeptr) { static c ...
- 【MySQL】ERROR 1045 (28000): Access denied for user的解决方法
去官网下载压缩版的MySQL Server,解压配置path环境变量后.然后克隆my-default.ini创建my.ini文件,在文件中[mysqld]下面配置basedir和datadir bas ...
- R语言实现数据集某一列的频数统计——with和table
with(priority.train, table(From.EMail)) 统计priority.train中From.EMail的频数