检查元素状态

 1 # -*- coding:utf-8 -*-
 2 """
 3 is_enabled():检查元素是否启用
 4 is_selected():检查元素是否选中(单选,多选,下拉框)
 5 is_displayed():检查元素是否可见
 6 """
 7 
 8 from selenium import webdriver
 9 
10 driver = webdriver.Firefox()
11 driver.get(r'F:\电子书\selenium\Selenium Testing Tools Cookbook(中文)\demo\RadioButton.html')
12 
13 apple = driver.find_element_by_css_selector("input[value='Apple']")
14 
15 #检查是否已选择,如果没有则点击选择
16 if not apple.is_selected():
17     apple.click()
18 
19 #验证 apple 选项已经选中    
20 assert True, apple.is_selected()
21 
22 fruit = driver.find_elements_by_name('fruit')
23 for allFruit in fruit:
24     if allFruit.get_attribute('value') == 'Orange':
25         if not allFruit.is_selected():
26             allFruit.click()
27             assert True, allFruit.is_selected()
28             break

 

posted @ 2013-07-06 21:38  Roger|  阅读(188)  评论(0编辑  收藏  举报