how to verify the drop down value using asserts in selenium when the HTML element is not Select class

1.8k Views Asked by At

i have an HTML element which is not select element. so i want to verify all the dropdown list using soft assert.

This is the code which i tried but it works only for select HTML element.

         String[] exp = {"--None--","Open","Closed","Priority-Reopened","Researching","Updated","Escalated"};
         WebElement dropdown = threadWebDriver.get().findElement(By.id("ddlNights"));  
         Select select = new Select(dropdown);  

         List<WebElement> options = select.getOptions();  
         for(WebElement we:options)  
         {  
          boolean match = false;
          for (int i=0; i<exp.length(); i++){
              if (we.getText().equals(exp[i]){
                match = true;
              }
            }
          Assert.assertTrue(match);
         }  

HTML element for this is given below:-

<a aria-required="true" class="select" aria-disabled="false" aria-describedby="2295:0-label" aria-haspopup="true" tabindex="0" role="button" title="" data-aura-rendered-by="2305:0" href="javascript:void(0);" data-interactive-lib-uid="9">Open</a>

How i can verify the list of drop down values?

1

There are 1 best solutions below

0
supputuri On

I would take another approach of checking if the dropdown have any of the values specified using xpath like this.

//*[@id='ddlNights'][contains('--None--,Open,Closed,Priority-Reopened,Researching,Updated,Escalated',a)]

Screenshot:

enter image description here

You can check if the element exist with the above xpath. That validates true if any of the list items present otherwise it will be false. You have to handle that assertion using softAssertion.