簡體   English   中英

angular js下拉列表中的Python硒選擇選項

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

請打開此網站-https : //mobikwik.com/
移動設備有一個表格,其中第二項是“選擇操作員”。
我想使用Selenium Webdriver從下拉菜單中選擇“ Idea”。
請幫忙。

另外,在選擇想法之后,我將獲得一個新的下拉列表,用於選擇圈子。 需要為此選擇孟買。

我的嘗試:

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()

我在同一網頁上嘗試了此代碼並工作:

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

首先使選項面板可見是至關重要的,否則它將引發以下異常:

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

更新:

要選擇孟買選項:

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

首先單擊選擇框,然后選擇選項,以選擇需要單擊第三個孩子的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()

其他選項如下:

.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

選擇第一個選擇框后,有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