简体   繁体   中英

Selecting value from dropdown not working with angularJS application

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

I am trying to click on the arrow and select an option from the dropdown. Approach I am following is, first I will click on '//span[@id='Select2_arrow']' followed by an option from the dropdown.

This is working fine for chrome and IE. But when it comes to Mozilla, clicking on the arrow works but while selecting an option from the dropdown. Clicking the option works and this step is passed. But actually option is not getting selected.

xpath for option is //*[@class='enabled _msddli_']//*[@class="ddlabel" and text()="General Question"]

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

HTML for the option inside the dropdown class. Note:I do not want to use javascriptexecutors.

You can change the xpath for the option here.

//span[text()='General Question']

Also you can use different locators like css selector. Please find code to access the option by iterating thorugh the list of options:

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);
            }
         }

Although iterating through dropdown takes some time,you can give it a try!! Hope this helps!!

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