selenium學(xué)習(xí):多表單的切換

文件:frame.html

從策劃到設(shè)計(jì)制作,每一步都追求做到細(xì)膩,制作可持續(xù)發(fā)展的企業(yè)網(wǎng)站。為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、空間域名、虛擬主機(jī)、網(wǎng)絡(luò)營銷、VI設(shè)計(jì)、 網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,以客戶的口碑塑造優(yōu)易品牌,攜手廣大客戶,共同發(fā)展進(jìn)步。

<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,內(nèi)嵌,因此需切換到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,內(nèi)嵌,因此需切換到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()默認(rèn)直接獲取表單的id或name屬性,若iframe無可用的id活name,則可以通過下述方法進(jìn)行定位:

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

當(dāng)前名稱:selenium學(xué)習(xí):多表單的切換
文章來源:http://bm7419.com/article32/gihosc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器定制網(wǎng)站、軟件開發(fā)、外貿(mào)網(wǎng)站建設(shè)網(wǎng)站營銷、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)