一种通过value的值:
def a(self,driver,element,value):
xpath = '//option[@value="'+value+'"]'
select = driver.find_element_by_xpath(element) #查找到select控件,这里通过xpath查找
select.find_element_by_xpath(xpath).click()
一种通过下拉框文本:
def b(self,driver,element,value):
select = driver.find_element_by_id(element) #查找到select控件,这里通过id查找
options = select.find_elements_by_tag_name("option")
for option in options:
if option.get_attribute("textContent").encode("utf-8") == value:
option.click()
break
网友评论