单选按钮处理

 1 # -*- coding:utf-8 -*-
 2 
 3 from selenium import webdriver
 4 
 5 driver = webdriver.Firefox()
 6 
 7 driver.get(r'F:\电子书\selenium\Selenium Testing Tools Cookbook(中文)\demo\RadioButton.html')
 8 
 9 apple = driver.find_element_by_css_selector("input[value='Apple']")
10 
11 #检查是否已选择
12 print apple.is_selected()
13 
14 #检查是否已选择,如果没有则点击选择
15 if not apple.is_selected():
16     apple.click()
17     
18 print apple.is_selected()
19 
20 #得到所有的单选按钮
21 fruit = driver.find_elements_by_name('fruit')
22 
23 #查询 Orange 选项是否存在,如果存在则选择
24 for allFruit in fruit:
25     if allFruit.get_attribute('value') == 'Orange':
26         if not allFruit.is_selected():
27             allFruit.click()
28             break

 

posted @ 2013-06-30 22:18  Roger|  阅读(172)  评论(0编辑  收藏  举报