How to find element for the dropdown list which is using ajax

<div class="ui-selectmenu-menu" style="z-index: 1; top: 457px; left: 1084.96px;">
     <ul class="ui-widget ui-widget-content ui-selectmenu-menu-dropdown ui-corner-bottom selectmenu form-control form-select ajax-processed" aria-hidden="true" role="listbox" aria-labelledby="edit-quantity-left-eye-button" id="edit-quantity-left-eye-menu" style="width: 113px; height: 200px;" aria-disabled="false" aria-activedescendant="ui-selectmenu-item-850">
         <li role="presentation" class="ui-selectmenu-item-selected ui-selectmenu-item-focus">
            <a href="#nogo" tabindex="-1" role="option" aria-selected="true" id="ui-selectmenu-item-850">0</a>
         </li>
         <li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">1</a></li><li role="presentation">
            <a href="#nogo" tabindex="-1" role="option" aria-selected="false">2</a>
         </li>
         <li role="presentation">
              <a href="#nogo" tabindex="-1" role="option" aria-selected="false">3</a>
         </li>
         <li role="presentation">
              <a href="#nogo" tabindex="-1" role="option" aria-selected="false">4</a>
         </li>
         <li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">5</a></li><li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">6</a></li><li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">7</a></li><li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">8</a></li><li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">9</a></li><li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">10</a></li><li role="presentation"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">11</a></li><li role="presentation" class="ui-corner-bottom"><a href="#nogo" tabindex="-1" role="option" aria-selected="false">12</a>
</li>
</ul>
</div>

I have tried using the Xpath its not working

//li[@role='presentation' and contains (@role, 'option')]

As the code is in ajax how to identify the element for this code.

1 answer

  • answered 2021-06-20 15:36 cruisepandey

    In Selenium Java - I would do this :

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("ui.ui-selectmenu-menu"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("2"))).click();
    

    We can not use Select class from Selenium since, the drop HTML does not contain Select and option tag.