简体   繁体   English

angular js下拉列表中的Python硒选择选项

[英]Python selenium select option from angular js drop down

Please open this website- https://mobikwik.com/ 请打开此网站-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. 我想使用Selenium Webdriver从下拉菜单中选择“ Idea”。
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 : 首先单击选择框,然后选择选项,以选择需要单击第三个孩子的vodafone:

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 选择第一个选择框后,有2个选择框,您可以相同地选择它,但是可以通过find_elements_by_css_selector()其选中

# 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中选择

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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