码迷,mamicode.com
首页 > 编程语言 > 详细

selenium python (十二)下拉框的处理

时间:2015-12-07 00:19:53      阅读:950      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = ‘zuoanvip‘

#下拉框在web页面上非常常见,对于下拉框的处理采用二次定位的方法进行元素定位:首先定位到下拉框,然后再定位下拉框的具体元素
from selenium import webdriver
import  os
import  time

driver = webdriver.Firefox()
file_path = ‘file:///‘+os.path.abspath(‘drop_down.html‘)
driver.get(file_path)

#首先定位到下拉框
drop_down = driver.find_element_by_id(‘ShippingMethod‘)

# 再点击下拉框到的选项
drop_down.find_element_by_xpath(‘//option[@value=‘10.69‘]‘).click()
time.sleep(5)
driver.quit()

 

============================================

drop_down.html源码

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

selenium python (十二)下拉框的处理

标签:

原文地址:http://www.cnblogs.com/dvbbs2012/p/5024595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!