マルチセレクション処理

5259 ワード

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