本文整理汇总了Python中selenium.webdriver.support.ui.Select.index方法的典型用法代码示例。如果您正苦于以下问题:Python Select.index方法的具体用法?Python Select.index怎么用?Python Select.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.Select
的用法示例。
在下文中一共展示了Select.index方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSelData
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def getSelData(el, Detailstr):
"""
选择查询条件的数据项
:param el:
:param Detailstr:
:return:
"""
time.sleep(1)
dataList = Select(el.get()).options
for i in range(len(dataList)):
#if dataList[i].text.strip() == Detailstr.strip():
if Detailstr.strip() in dataList[i].text:
#time.sleep(1)
#value = dataList[i].get_attribute('value')
#Select(el.get()).select_by_value(value)
index=dataList.index(dataList[i])
Select(el.get()).select_by_index(index)
break
else:
logging.error(u'没有数据'+Detailstr+u',请确认')
exit(u'没有此数据,请确认')
示例2: SubmitApproval
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def SubmitApproval(self,func,el,sub):
self.clickFunction(func,el,sub,key)
sleep(5)
self.bSwithcfrname(el, key)
self.tabcheck(el)
a = EL.get_el_list('RPdataDetail', cg.path)
self.checkKeys(func, el, key,sub)
el.getFunctionName(a[0])
el.get_element('selWorkFlow')
currentscttext = Select(el.get()).all_selected_options[0].text
if u'请选择' in currentscttext:
rdmod = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdmod)
logging.info(Select(el.get()).all_selected_options[0].text)
else:
selOption = Select(el.get()).all_selected_options
allOptions = Select(el.get()).options
if selOption[0] in allOptions:
index = allOptions.index(selOption[0])
while True:
rd = random.randint(1, len(allOptions) - 1)
if index != rd:
Select(el.get()).select_by_index(rd)
el.get_element('SubmitApproval')
el.get().click()
func.driver.switch_to.default_content()
sleep(2)
#print func.driver.current_url
txtT=func.driver.find_element_by_xpath('/html/body/div[1]/table/tbody/tr[2]/td[2]/div/table/tbody/tr[1]/td/div/div[1]').text
if txtT==u'新增报告':
txtT=func.driver.find_element_by_xpath('/html/body/div[1]/table/tbody/tr[2]/td[2]/div/table/tbody/tr[1]/td/div/div[1]').text
#print txtT
if txtT==u'从默认审批人中指定':
func.driver.find_elements_by_xpath('//*[@id="field_status"]')[0].find_element_by_xpath('input').click()
else:
self.choices_Auser(func,el)
示例3: NewCopyDetail
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def NewCopyDetail(self,el,args=None,ButtonKey=None,Inquiry=None):
"""
复制新增功能
:param self:
:param el: Element类对象
:param args: 参数组,
:param ButtonKey: 操作的按钮,默认为保存
:param Inquiry: 询价方式
:return:
"""
if Inquiry == None:
commond.Duantao(self, el)
else:
commond.OtherXujia(self, el, Inquiry)
commond.LinkDate(el)
el.getFunctionName(dataCopyNew[0])
el.get_element(dataCopyNew[1])
el.get().click()
self.driver.switch_to.default_content()
el.getFunctionName(MsgFrm[0])
el.get_element(MsgFrm[1])
xf = el.get()
self.driver.switch_to.frame(xf)
el.getFunctionName(dataDetail[0])
el.get_element('jishutuandui')
'''
#当前技术团队项为
currentseltext = Select(el.get()).all_selected_options[0].text
print currentseltext
if u'请选择' in currentseltext:
rd = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rd)
#Select(el.get()).all_selected_options[0].text
'''
# 技术团队
#el.get_element('jishutuandui')
if len(Select(el.get()).options) < 2:
el.get_element('weituoleixing')
selOption = Select(el.get()).all_selected_options
allOptions = Select(el.get()).options
print allOptions
if selOption[0] in allOptions:
index = allOptions.index(selOption[0])
while True:
rd = random.randint(1, len(allOptions) - 1)
if index != rd:
Select(el.get()).select_by_index(rd)
break
# 当前技术团队项
el.get_element('jishutuandui')
currentseltext = Select(el.get()).all_selected_options[0].text
if u'请选择' in currentseltext:
rd = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rd)
logging.info(u'技术团队:' + Select(el.get()).all_selected_options[0].text)
el.get_element('shenfen')
selProvince=Select(el.get()).all_selected_options[0].text
if u'请选择'in selProvince:
rdP = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdP)
el.get_element('chengshi')
rdC = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdC)
el.get_element('xingzhengqu')
rdX = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdX)
el.get_element('quyu')
rdQ = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdQ)
el.get_element('chengshi')
field_cityid=Select(el.get()).all_selected_options[0].text
if u'请选择' in field_cityid:
rdC = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdC)
el.get_element('xingzhengqu')
rdX = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdX)
el.get_element('quyu')
rdQ = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdQ)
el.get_element('xingzhengqu')
field_areaid=Select(el.get()).all_selected_options[0].text
if u'请选择' in field_areaid:
rdX = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdX)
el.get_element('quyu')
rdQ = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdQ)
#.........这里部分代码省略.........
示例4: Query
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def Query(self,el,msgmode=None,data=None,submode=None,Inquiry=None,substate=None):
"""
:param self:
:param el:
:param msgmode:
:param data:
:param submode:
:param Inquiry:
:param substate:
:return:
"""
if Inquiry == None:
commond.Duantao(self,el,submode,substate)
else:
commond.OtherXujia(self,el,Inquiry,substate)
el.getFunctionName(query[0])
if Inquiry!='Gaizhang':
if substate!='daishenpi'and substate!='yishenpi':
el.get_element('moreConditions')
el.get().click()
elementList = []
resultText=''
if data==u'默认':
data=msgmode
logging.info(u'查询关键字为:%s'%msgmode)
if msgmode==u'省份':
if data==None:
pass
else:
for i in [u'直辖市',u'省',u'特区',u'自治区']:
if i in data:
if u'直辖市' in data or u'特区' in data:
if u'直辖市' in data:
provinceKey=u'直辖市'
city = data.split(provinceKey)[0] + u'市'
else:
provinceKey=u'特区'
city = data.split(provinceKey)[0]
dataprList=data.split(provinceKey)
provincetext=data.split(provinceKey)[0]+provinceKey
el.get_element('province')
provinceList=Select(el.get()).options
for i in range(len(provinceList)):
if provinceList[i].text.strip()==provincetext:
value=provinceList[i].get_attribute('value')
Select(el.get()).select_by_value(value)
#index=provinceList.index(provinceList[i])
#Select(el.get()).select_by_index(index)
#time.sleep(5)
break
el.get_element('city')
cityList=Select(el.get()).options
for i in range(len(cityList)):
if cityList[i].text.strip()==city:
index=cityList.index(cityList[i])
Select(el.get()).select_by_index(index)
break
if len(dataprList)>=2:
area=data.split(provinceKey)[1]
el.get_element('area')
areaList=Select(el.get()).options
for i in range(len(areaList)):
if areaList[i].text.strip()==area:
index=areaList.index(areaList[i])
Select(el.get()).select_by_index(index)
break
else:
if u'省' in data:
provinceKey=u'省'
elif u'自治区' in data:
provinceKey =u'自治区'
else:
logging.error(u'数据格式不正确,请确认')
exit(u'数据格式不正确,请确认')
dataprList = data.split(provinceKey)
provincetext = dataprList[0] + provinceKey
el.get_element('province')
getSelData(el, provincetext)
el.get_element('city')
if dataprList[1]!='':
if u'市' in dataprList[1]:
cityKey=u'市'
elif u'县' in dataprList[1]:
cityKey=u'地区'
elif u'州' in dataprList[1]:
cityKey =u'自治州'
elif u'盟' in dataprList[1]:
cityKey=u'盟'
cityList = dataprList[1].split(cityKey,1)
city = cityList[0]+ cityKey
#.........这里部分代码省略.........
示例5: WritePreviews
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def WritePreviews(self,el,msgElement=None,data=None,link=None,submode=None,Inquiry=None):
if Inquiry == None:
commond.Duantao(self, el, submode)
dataId=JudgeTOBData(el,link)
#commond.switchToDetailUI(self, el)
el.getFunctionName(ExamineModif[0])
el.get_element('writePreviews')
el.get().click()
time.sleep(1)
self.driver.switch_to.default_content()
el.get_element('transferOfBusinessiframe')
self.driver.switch_to.frame(el.get())
el.getFunctionName(ExamineModif[0])
# 查看是否Tab显示
el.get_element('pReevaluateTab')
tabatb = el.get().get_attribute('class')
logging.info(u'查看是否为Tab方式')
if 'chked' in tabatb:
el.get_element('tabchkbox')
el.get().click()
time.sleep(1)
if msgElement!='jishutuandui':
# 技术团队
el.get_element('jishutuandui')
if len(Select(el.get()).options) < 2:
el.get_element('weituoleixing')
selOption = Select(el.get()).all_selected_options
allOptions = Select(el.get()).options
if selOption[0] in allOptions:
index = allOptions.index(selOption[0])
while True:
rd = random.randint(1, len(allOptions) - 1)
if index != rd:
Select(el.get()).select_by_index(rd)
break
time.sleep(1)
el.get_element('jishutuandui')
currentseltext = Select(el.get()).all_selected_options[0].text
if u'请选择' in currentseltext:
rd = random.randint(1, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rd)
logging.info(u'技术团队:' + Select(el.get()).all_selected_options[0].text)
if msgElement!='yewubumen':
##业务部门
el.get_element('yewubumen')
currentseltext = Select(el.get()).all_selected_options[0].text
if u'请选择' in currentseltext:
rd = random.randint(1, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rd)
logging.info(u'业务部门:' + Select(el.get()).all_selected_options[0].text)
if msgElement!='baogaoleixing':
##报告类型
el.get_element('baogaoleixing')
currentseltext = Select(el.get()).all_selected_options[0].text
if u'请选择' in currentseltext:
rd = random.randint(1, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rd)
logging.info(u'报告类型:' + Select(el.get()).all_selected_options[0].text)
#time.sleep(5)
#if msgElement !=None:
#.get_element(msgElement)
if msgElement != None:
currenttext=''
el.get_element(msgElement)
dictFunction = EL.get_el_dict(ExamineModif[0], msgElement, xmlpath)
try:
el.get().get_attribute('tagname')
except:
raise (u'未找元素,请确认')
if 'elementType' in dictFunction:
if dictFunction['elementType'] == 'select':
currentscttext = Select(el.get()).all_selected_options[0].text
if data == None:
if u'请选择' in currentscttext:
rdmod = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdmod)
logging.info(Select(el.get()).all_selected_options[0].text)
else:
selOption = Select(el.get()).all_selected_options
allOptions = Select(el.get()).options
if selOption[0] in allOptions:
index = allOptions.index(selOption[0])
while True:
rd = random.randint(1, len(allOptions) - 1)
if index != rd:
Select(el.get()).select_by_index(rd)
elif data in currentscttext and u'请选择' not in currentscttext:
pass
else:
allOptions = Select(el.get()).options
for selem in allOptions:
if data == selem.text:
index = allOptions.index(selem)
#.........这里部分代码省略.........
示例6: ModificationData
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def ModificationData(self,el,msgmode=None,data=None,link=None,submode=None,button=None,Inquiry=None):
"""
修改数据验证
:param self:
:param el:
:param msgmode:元素在xml的名称
:param data: 输入数据
:param link: 环节
:param submode: 单套询价类型
:param button: 按钮
:param Inquiry: 询价类型
:return:
"""
if Inquiry == None:
commond.Duantao(self, el, submode)
# commond.Switchto_Frame(self, Inquiry)
# currentuser = commond.sessionName
# valuer = commond.Valuer
dataId=ModificationClickLinkData(el,link=link)
commond.switchToDetailUI(self, el)
'''
if button == 'writePreviews':
el.getFunctionName(ExamineModif[0])
el.get_element(msgmode)
el.get().click()
'''
addnew.checkTab(el)#查看是否Tab显示
el.getFunctionName(ExamineModif[0])
el.get_element(msgmode)
commond.GetDetail(self, el, ExamineModif, msgmode)
if msgmode != None:
currenttext=''
el.get_element(msgmode)
dictFunction = EL.get_el_dict(ExamineModif[0], msgmode, xmlpath)
try:
el.get().get_attribute('tagname')
except:
raise (u'未找元素,请确认')
if 'elementType' in dictFunction:
if dictFunction['elementType'] == 'select':
currentscttext = Select(el.get()).all_selected_options[0].text
# logging.info(currenttext)
if data == None:
if u'请选择' in currentscttext:
rdmod = random.randint(2, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdmod)
logging.info(Select(el.get()).all_selected_options[0].text)
else:
selOption = Select(el.get()).all_selected_options
allOptions = Select(el.get()).options
if selOption[0] in allOptions:
index = allOptions.index(selOption[0])
while True:
rd = random.randint(1, len(allOptions) - 1)
if index != rd:
Select(el.get()).select_by_index(rd)
elif data in currentscttext and u'请选择' not in currentscttext:
pass
else:
allOptions = Select(el.get()).options
for selem in allOptions:
if data == selem.text:
index = allOptions.index(selem)
Select(el.get()).select_by_index(index)
break
else:
logging.info(u'选项中没有输入的项,请确认!')
exit(u'选项中没有输入的项,请确认!')
currenttext=Select(el.get()).all_selected_options[0].text
elif dictFunction['elementType'] == 'input' or dictFunction['elementType'] == 'textarea':
el.get().clear()
el.get().send_keys(data)
currenttext = el.get().get_attribute('value')
else:
el.get().clear()
el.get().send_keys(data)
currenttext = el.get().text
logging.info(u'输入:'+currenttext)
el.getFunctionName(MsgBtn[0])
el.get_element('save')
el.get().click()
self.driver.switch_to.default_content()
time.sleep(1)
'''
el.get_element('close')
el.get().click()
'''
modification_lookData(self,el,dataId,Inquiry)
commond.switchToDetailUI(self,el)
newtext=commond.GetDetail(self, el, ExamineModif, msgmode)
return data==newtext
else:
commond.OtherXujia(self, el, Inquiry)
示例7: reportadd
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def reportadd(self,func,el,sub,button=None,**args):
oldIDlist=self.clickFunction(func,el,sub,key)
sleep(3)
self.bSwithcfrname(el,key)
self.tabcheck(el)
RPdataDetail = EL.get_el_list('RPdataDetail', cg.path)
currenttxtList=[]
self.checkKeys(func, el, key,sub)
#通过字典类型来判断数据类型,通过字典的值来填写数据
if u'委托客户' in args.keys():
if u'委托客户分行' in args.keys() and len(args.keys())>=3:
wtkh=[u'委托客户',u'委托客户分行',u'委托客户支行']
else:
wtkh=args.keys()
for i in wtkh:
for j in range(1, len(RPdataDetail)):
RPdataDetaildict = EL.get_el_dict(RPdataDetail[0], RPdataDetail[j], cg.path)
if RPdataDetaildict.get('name').strip() == i.strip():
el.getFunctionName(RPdataDetail[0])
el.get_element(RPdataDetail[j])
currentscttext = Select(el.get()).all_selected_options[0].text
if args[i] == None:
if u'请选择' in currentscttext:
rdmod = random.randint(1, len(Select(el.get()).options) - 1)
Select(el.get()).select_by_index(rdmod)
logging.info(Select(el.get()).all_selected_options[0].text)
else:
selOption = Select(el.get()).all_selected_options
allOptions = Select(el.get()).options
if selOption[0] in allOptions:
index = allOptions.index(selOption[0])
while True:
rd = random.randint(1, len(allOptions) - 1)
if index != rd:
Select(el.get()).select_by_index(rd)
elif args[i] in currentscttext and u'请选择' not in currentscttext:
pass
else:
allOptions = Select(el.get()).options
for selem in allOptions:
if args[i].strip() == selem.text.strip():
index = allOptions.index(selem)
Select(el.get()).select_by_index(index)
sleep(1)
break
else:
logging.error(u'未找到此选项:' + args[i])
exit(u'未找到此选项:' + args[i])
currenttxtList.append(args[i])
break
else:
logging.error(u'not found:' + i)
currenttxtList.append('false')
else:
for i in args.keys():
if i.strip() == u'评估方法':
if type(args[i]) == list:
pass
else:
if args[i]==u'比较法':
if func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[1]').get_attribute('checked')!='true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[1]').click()
currenttxtList.append(u'比较法')
elif args[i]==u'收益法':
if func.driver.find_element_by_xpath(
'//*[@id="field_valuationmethods"]/input[2]').get_attribute('checked') != 'true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[2]').click()
currenttxtList.append(u'收益法')
elif args[i]==u'成本法':
if func.driver.find_element_by_xpath(
'//*[@id="field_valuationmethods"]/input[3]').get_attribute('checked') != 'true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[3]').click()
currenttxtList.append(u'成本法')
elif args[i]==u'假设开发法':
if func.driver.find_element_by_xpath(
'//*[@id="field_valuationmethods"]/input[4]').get_attribute('checked') != 'true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[4]').click()
currenttxtList.append(u'假设开发法')
elif args[i]==u'基准地价修正法':
if func.driver.find_element_by_xpath(
'//*[@id="field_valuationmethods"]/input[5]').get_attribute('checked') != 'true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[5]').click()
currenttxtList.append(u'基准地价修正法')
elif args[i]==u'路线价法':
if func.driver.find_element_by_xpath(
'//*[@id="field_valuationmethods"]/input[6]').get_attribute('checked') != 'true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[6]').click()
currenttxtList.append(u'路线价法')
elif args[i]==u'长期趋势法':
if func.driver.find_element_by_xpath(
'//*[@id="field_valuationmethods"]/input[7]').get_attribute('checked') != 'true':
func.driver.find_element_by_xpath('//*[@id="field_valuationmethods"]/input[7]').click()
currenttxtList.append(u'长期趋势法')
else:
for j in range(1, len(RPdataDetail)):
RPdataDetaildict=EL.get_el_dict(RPdataDetail[0], RPdataDetail[j], cg.path)
if RPdataDetaildict.get('name').strip()==i.strip():
el.getFunctionName(RPdataDetail[0])
#.........这里部分代码省略.........
示例8: parse
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import index [as 别名]
def parse(self, response):
self.driver.get(response.url)
select = Select(self.driver.find_element_by_xpath('//*[@id="selectedSubjects"]'))
num_options = len(select.options)
json_data = []
# Iterate over each subject listed in the combobox
for i in range(num_options - 1):
self.driver.get(response.url)
# Wait for subjects appear in options box, then click
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="selectedSubjects"]'))
)
Select(self.driver.find_element_by_xpath('//*[@id="selectedSubjects"]')).select_by_index(i)
subject_selection = Select(self.driver.find_element_by_xpath('//*[@id="selectedSubjects"]')).options[i].text
course_subject_long = subject_selection[(subject_selection.index('-') + 2):]
course_subject = subject_selection[:(subject_selection.index('-') - 1)]
# Hit submit to get courses for that subject
self.driver.find_element_by_xpath('//*[@id="socFacSubmit"]').click()
# Try to get the number of pages for this subject
try:
total_page_number = scrapy.Selector(text=unicode(self.driver.page_source)).xpath(
'//*[@id="socDisplayCVO"]/div[2]/table/tbody/tr/td[3]/text()[1]').extract_first(default='f 0)')
total_page_number = int(
total_page_number[(total_page_number.index('f') + 2):total_page_number.index(')')])
except:
total_page_number = 0
# Iterate over each page in for the results of this subject
for j in range(1, total_page_number + 1):
self.driver.get('https://act.ucsd.edu/scheduleOfClasses/scheduleOfClassesStudentResult.htm?page=' +
str(j))
result_selector = scrapy.Selector(text=self.driver.page_source.encode('utf-8'))
course_selectors = result_selector.xpath('//*[@id="socDisplayCVO"]/table/tbody/tr/td[3]/a/span')
# Iterate over each course selector. Its neighbor element will give the professor name (cant get any
# other way)
for selector in course_selectors:
course_title = unicode(selector.xpath('.//text()').extract_first(default=''))
if ' ' in course_title:
course_title = course_title[:course_title.index(' ')]
course_number = unicode(selector.xpath(
'.//ancestor::td[1]/preceding-sibling::td[1]/text()').extract_first(
''))
professor_name = selector.xpath(
'.//ancestor::tr[1]//following-sibling::tr[1]/td/a/text()').extract_first(
default=None)
# Get non-linked version of name... TODO: not working
if not professor_name:
professor_name = selector.xpath(
'.//ancestor::tr[1]//following-sibling::tr[1]/td/text()').extract_first(
default=None
)
if not re.search('[a-zA-z]', professor_name):
professor_name = ''
professor_name = unicode(professor_name)
professor_name = (professor_name[:professor_name.index(' ')] if professor_name else '')
json_data.append(
{
"courseSubject": course_subject,
"courseSubjectLong": course_subject_long,
"courseName": course_title,
"courseNumber": course_number,
"professorName": professor_name
}
)
self.data.write(unicode(json.dumps(json_data, indent=4)))