webdriver下拉框中选择option的方法提醒

 

select这个标签比较特殊

下面的option不能用点击下拉框,再点击选中这种方法

前端代码:

<html>

<body>

<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>

</body>

</html>

脚本代码:

#-*-coding=utf-8

from selenium import webdriver

import os,time

driver= webdriver.Firefox()

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

driver.get(file_path)

time.sleep(2)

m=driver.find_element_by_id("ShippingMethod")

m.find_element_by_xpath("//option[@value='10.69']").click()

time.sleep(3)

driver.quit()


正确思路是:先定位上级select(不用点击哦),再点击要选择的内容

 

posted @ 2016-12-09 20:13  龙心呢  阅读(1333)  评论(0编辑  收藏  举报