文件:frame.html

從策劃到設計制作,每一步都追求做到細膩,制作可持續發展的企業網站。為客戶提供網站設計、成都網站制作、網站策劃、網頁設計、空間域名、虛擬主機、網絡營銷、VI設計、 網站改版、漏洞修補等服務。為客戶提供更好的一站式互聯網解決方案,以客戶的口碑塑造優易品牌,攜手廣大客戶,共同發展進步。
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link />
<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()
本文標題:selenium學習:多表單的切換
新聞來源:http://www.yijiale78.com/article32/gihosc.html
成都網站建設公司_創新互聯,為您提供微信小程序、域名注冊、搜索引擎優化、網頁設計公司、網站營銷、商城網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯