2016-04-11 20 views
0
<div id="Select2_msdd" class="dd ddcommon form-control form-control-gender form-control-input styled-select-dd-lrg ng-isolate-scope ng-pristine ng-valid ng-invalid ng-dirty borderRadius" tabindex="0" style="z-index: 1; background-color: rgb(255, 255, 255);"> 
<div class="ddTitle borderRadiusTp"> 
<span class="divider"></span> 
<span id="Select2_arrow" class="ddArrow arrowoff"></span> 

我試圖單擊箭頭並從下拉列表中選擇一個選項。我遵循的方法是,首先,我將點擊'//span[@id='Select2_arrow']',然後從下拉菜單中選擇一個選項。從下拉列表中選擇與angularJS應用程序不兼容的值

這對鉻和IE工作正常。但是當涉及到Mozilla時,點擊箭頭可以工作,但從下拉列表中選擇一個選項。點擊該選項,並且這一步通過。但實際上選項沒有被選中。

的XPath的選擇是//*[@class='enabled _msddli_']//*[@class="ddlabel" and text()="General Question"]

<li class="enabled _msddli_"> 
<span class="ddlabel" style="background-color: transparent;">General Question</span> 

HTML的下拉類中的選項。 注意:我不想使用javascriptexecutors。

+0

是否存在'>'HTML'代碼中存在的元素? – Andersson

+0

請在dd中選擇選項之前嘗試做一個預期的等待,可以幫助\ –

+0

@Andersson感謝您的回覆。沒有 – manutd

回答

-1

您可以在此處更改此選項的xpath。

//跨度[文本()= '常規問題']

您也可以使用不同的定位器如CSS選擇器。 請找代碼通過遍歷thorugh的選項列表訪問選項:

String str="General Question"; 

Select list= new Select(driver.findElement(By.id("mention the drop down locator you are using"))); 
     List<WebElement> listSize = list.getOptions(); 
     int iListSize = listSize.size(); 
     // System.out.println(iListSize); 

     // Setting up the loop to select all the options 
      for(int j =0; j < iListSize ; j++){ 
      // Storing the value of the option 
      String sValue = list.getOptions().get(j).getText(); 

      // Selecting all the elements one by one 
     if (sValue.equalsIgnoreCase(str){ 
      list.selectByVisibleText(sValue); 
      Thread.sleep(50); 
      } 
     } 

雖然通過下拉迭代需要一些時間,你可以試試看!希望這可以幫助!!

+1

1- OP沒有要求對所有選項進行迭代2-'選擇'只能在'