i have a drop down list that i add items to it,i ask the user to type in brand name and check first if that brand is already found on the drop down list if yes prints a message if no do some actions. here is the code:
def add_brand(self,x):
self.elem=self.driver.find_element_by_id('MainContent_txtBrand')
self.elem.send_keys(x)
self.txt=self.driver.find_element_by_id('MainContent_ddlBrand')
self.brands=self.txt.find_elements_by_tag_name('option')
for i in self.brands:
if i.text==x:
print('already found')
break
else:
print('this item is new')
self.driver.find_element_by_id('MainContent_hlSaveBrand').click()
self.driver.find_element_by_id('MainContent_txtBrand').clear()
break
and here is the code to call that function:
no=input('enter how many brands u want to add')
store.add_brand_model_item()
for i in range (0,no):
koko=raw_input('plz enter brand name')
store.add_brand(koko)
print("x >"+x+"< i.text >"+i.text+"<")
before the if? – user246 Nov 28 '12 at 15:19