selenium学习:多表单的切换

发布时间:2020-07-06 18:19:07 作者:91ctt
来源:网络 阅读:1963

文件:frame.html

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<script type="text/javascript">$(document).ready(function(){});>
</script>
</head>
<body>
	<div class="row-fluid">  		
		<div class="span10 wel">
			<h4>frame</h4>
				<iframe id="if" name="nf" src="http://www.baidu.com" width="800" height="300">					
				</iframe>	
		</div>	  
	</div>  
</body>	
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js">
</script>
</html>

文件:test11.py

from selenium import webdriver

import os,time

driver = webdriver.Chrome()

file_path='file:///'+os.path.abspath('frame.html')

driver.get(file_path)


#由于使用的是iframe,内嵌,因此需切换到iframe(id="if")

from selenium import webdriver
import os,time
driver = webdriver.Chrome()
file_path='file:///'+os.path.abspath('frame.html')
driver.get(file_path)

#由于使用的是iframe,内嵌,因此需切换到iframe(id="if")
driver.switch_to.frame("if")
time.sleep(3)
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
driver.quit()

swith_to_frame()默认直接获取表单的id或name属性,若iframe无可用的id活name,则可以通过下述方法进行定位:

xf=driver.find_element_by_path('//*[@class="if"]')
driver.switch_to.frame(xf)
driver.switch_to_.parent_frame()


推荐阅读:
  1. selenium-5 多窗口切换
  2. selenium学习:操作Cookie

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

selenium sel

上一篇:一个基于Emgu的运动检测实例

下一篇:mt_rand() 函数

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》