文件: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()
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。