简体   繁体   中英

Python selenium select option from angular js drop down

Please open this website- https://mobikwik.com/
There is a form for Mobile with 2nd item as Select Operator.
I want to select - "Idea" from this drop down using selenium webdriver.
Please help.

Also, after selecting idea, i get a new drop down for select circle. Need to select Mumbai for it.

My attempt:

driver.find_element_by_css_selector("li > span.ng-binding").click()
driver.find_element_by_xpath("//label[3]/i").click()
driver.find_element_by_css_selector("font > label > i").click()
driver.find_element_by_xpath("//section[@id='mainunit']/div/div[2]/div/div[2]/div/div/div/form/div[4]/p/dl/dd/ul/li[9]/span").click()
driver.find_element_by_xpath("//font/label[2]/i").click()

I tried this code with same webpage and worked:

driver.find_element_by_xpath("//span[contains(text(), 'Select Operator')]").click()
driver.find_element_by_xpath("//span[contains(text(), 'Idea')]/..").click()

It is essential that you first make visible the options pannel, otherwise it will throw the following exception:

selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with

Updated:

To select the Mumbai option:

driver.find_element_by_xpath("//span[contains(text(), 'Select Circle')]").click()
driver.find_element_by_xpath("//span[contains(text(), 'Mumbai')]/..").click()

first click the select box then choose the option, to choose the vodafone you need to click 3rd child :

driver.find_element_by_css_selector(".select").click()
driver.find_element_by_css_selector(".options > ul:nth-child(1) > li:nth-child(3)").click()

other options are as the following:

.options > ul:nth-child(1) > li:nth-child(2) => Artiel
.options > ul:nth-child(1) > li:nth-child(3) => Vodafone
.options > ul:nth-child(1) > li:nth-child(4) => BSNL

after you select the first select box there are 2 select box, you can select it samely but by find_elements_by_css_selector() with pulural

# select first one
driver.find_element_by_css_selector(".select").click()
driver.find_element_by_css_selector(".options > ul:nth-child(1) > li:nth-child(3)").click()
# select second selectbox
# you may need to sleep until second selectbox is available
sleep(1)
driver.find_elements_by_css_selector(".select")[1].click()
driver.find_element_by_css_selector(".options.open > ul:nth-child(1) > li:nth-child(5)").click() # 5 option is Mumbai

floorselectionWait = WebDriverWait(driver,20).until(EC.presence_of_element_located((By.XPATH,'//*[@id="select_22"]'))) floorselection=driver.find_element(By.XPATH,'//*[@id="select_22"]') floorselection.click() flooroptionsWait = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//DIV[@class='md-text ng-binding'][text()='Level 7']"))) optionSelect=driver.find_element(By.XPATH,"//DIV[@class='md-text ng-binding'][text()='Level 7']") optionSelect.click() angularjs md-select md-option在硒python中选择

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM