下拉列表框处理
1 # -*- coding:utf-8 -*-
2
3 """
4 下拉列表處理
5 """
6
7 from selenium import webdriver
8 from selenium.webdriver.support.select import Select
9
10 driver = webdriver.Firefox()
11
12 driver.get(r'F:\電子書\selenium\Selenium Testing Tools Cookbook(中文)\demo\Droplist.html')
13
14 #得到下拉列表框
15 make = Select(driver.find_element_by_name('make'))
16
17 #獲取下拉列表框的數(shù)量
18 print len(make.options)
19
20 #通過 value 屬性來選擇項
21 make.select_by_visible_text('Audi')
22
23 #通過索引來選擇項,索引值從0開始
24 make.select_by_index(2)
25
26 make.select_by_value('honda')
?
1 # -*- coding:utf-8 -*- 2 3 from selenium import webdriver 4 from selenium.webdriver.support.select import Select 5 6 driver = webdriver.Firefox() 7 8 driver.get('F:\電子書\selenium\Selenium Testing Tools Cookbook(中文)\demo\Droplist.html') 9 10 color = Select(driver.find_element_by_name('color')) 11 12 #驗證下拉列表支持多選 13 print color.is_multiple 14 15 #獲取下拉列表的數(shù)量 16 print len(color.options) 17 18 #使用可見的文本年來選擇項 19 color.select_by_visible_text('Black') 20 color.select_by_visible_text('Red') 21 color.select_by_visible_text('Silver') 22 23 #通過可見的文本取消已選選項 24 color.deselect_by_visible_text('Silver') 25 26 #通過選項索引取消已選選項 27 color.deselect_by_index(0) 28 29 for x in color.options: 30 print x.text?
?
轉(zhuǎn)載于:https://www.cnblogs.com/Roger1227/p/3162303.html
總結
- 上一篇: 统一指令集架构的思考
- 下一篇: 警告:failed to load th