多选框处理

 1 # -*- coding:utf-8 -*-
 2 """
 3 多选框处理
 4 """
 5 from selenium import webdriver
 6 from compiler.ast import Assert
 7 import unittest
 8 
 9 class Checkbox_Demo(unittest.TestCase):
10     def setUp(self):
11         self.driver = webdriver.Firefox()
12         self.driver.get(r'F:\电子书\selenium\Selenium Testing Tools Cookbook(中文)\demo\checkbox.html')
13 
14     def test_checkbox(self):
15         driver = self.driver
16         apple = driver.find_element_by_css_selector("input[value='Apple']")        
17         pear = driver.find_element_by_css_selector("input[value='Pear']")        
18         orange = driver.find_element_by_css_selector("input[value='Orange']")
19 
20         #检查是否已选择,如果没有则点击选择        
21         if not apple.is_selected():
22             apple.click()
23         
24         if not pear.is_selected():
25             pear.click()
26             
27         if not orange.is_selected():
28             orange.click()
29         
30         self.assertTrue(apple.is_selected())
31         self.assertTrue(pear.is_selected())
32         self.assertTrue(orange.is_selected())
33         
34         #检查是否已选择,如果已选择则点击取消选择
35         if apple.is_selected():
36             apple.click()
37         
38         self.assertTrue(apple.is_selected())
39 
40     def tearDown(self):
41         self.driver.quit()

 

posted @ 2013-07-01 20:05  Roger|  阅读(242)  评论(0编辑  收藏  举报