您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium---WebDriver學(xué)習(xí)筆記
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/4/16 15:33:00 ] 推薦標(biāo)簽:

1. 什么情況下使用WebDriver

multiple frames, multiple brower windows(多窗口瀏覽器), popups(彈出窗口) adn alerts
頁面導(dǎo)航
下拉
 基于AJAX的UI元素

2. WebDriver常用函數(shù)接口

1)頁面導(dǎo)航

driver.get("http://www.google.com")

完全裝載頁面后將控制返回給測試腳本。當(dāng)頁面中存在很多AJAX調(diào)用時(shí),該接口無法確認(rèn)頁面是否完全加載,需要使用“waits”

2)與頁面交互

<input type="text" name="passwd" id="passwd-id" />

driver = self.driver
driver.find_element_by_id("passwd-id").send_keys("******")
driver.find_element_by_xpath("//input[@id=’passwd-id’]")

關(guān)于xpath的知識(shí),會(huì)在以后再去學(xué)習(xí)。

關(guān)于下拉框的處理(測試代碼如下):

<select id="ShippingMethod" onchange="updateShipping(options[selectedIndex]);" name="ShippingMethod">
<option value="12.51">UPS Next Day Air ==> $12.51</option>
<option value="11.61">UPS Next Day Air Saver ==> $11.61</option>
<option value="10.69">UPS 3 Day Select ==> $10.69</option>
<option value="9.03">UPS 2nd Day Air ==> $9.03</option>
<option value="8.34">UPS Ground ==> $8.34</option>
<option value="9.25">USPS Priority Mail Insured ==> $9.25</option>
<option value="7.45">USPS Priority Mail ==> $7.45</option>
<option value="3.20" selected="">USPS First Class ==> $3.20</option>
</select>

使用select選擇需要使用的值,如 8.34

select=browser.find_element_by_xpath("//select[@id='ShippingMethod']")
select.find_element_by_xpath("//option[@value='8.34']").click()

先使用xpath定位所select,然后再確定使用的值

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd