JQueryUI Menu widget get all items of submenus with selenium

  • 0 Replies
  • 1111 Views
JQueryUI Menu widget get all items of submenus with selenium
« on: February 15, 2016, 14:45:54 pm »
I am trying to implement click/hover on a JQueryUI Menu widget

https://jqueryui.com/resources/demos/menu/default.html

A nested loop iterating over the first menu, and then next one seems doable. But then there's a third, and submenus could possibly go on

Assuming a user would give a text input of an item 3 submenus down from the main menu, how would i be able to write a method dynamic enough to find that item?

Code
<body>
<ul id="menu" class="ui-menu ui-widget ui-widget-content" role="menu" tabindex="0" aria-activedescendant="ui-id-9">
<li class="ui-state-disabled ui-menu-item" id="ui-id-1" tabindex="-1" role="menuitem" aria-disabled="true">Aberdeen</li>
<li class="ui-menu-item" id="ui-id-2" tabindex="-1" role="menuitem">Ada</li>
<li class="ui-menu-item" id="ui-id-3" tabindex="-1" role="menuitem">Adamsville</li>
<li class="ui-menu-item" id="ui-id-4" tabindex="-1" role="menuitem">Addyston</li>
<li aria-haspopup="true" class="ui-menu-item" id="ui-id-5" tabindex="-1" role="menuitem"><span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>Delphi
<ul class="ui-menu ui-widget ui-widget-content ui-front" role="menu" aria-expanded="false" style="display: none; top: -1px; left: 150px;" aria-hidden="true">
<li class="ui-state-disabled ui-menu-item" id="ui-id-6" tabindex="-1" role="menuitem" aria-disabled="true">Ada</li>
<li class="ui-menu-item" id="ui-id-7" tabindex="-1" role="menuitem">Saarland</li>
<li class="ui-menu-item" id="ui-id-8" tabindex="-1" role="menuitem">Salzburg an der schönen Donau</li>
</ul>
</li>
<li class="ui-menu-item" id="ui-id-9" tabindex="-1" role="menuitem">Saarland</li>
<li aria-haspopup="true" class="ui-menu-item" id="ui-id-10" tabindex="-1" role="menuitem"><span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>Salzburg
<ul class="ui-menu ui-widget ui-widget-content ui-front" role="menu" aria-expanded="false" style="display: none; top: -1px; left: 150px;" aria-hidden="true">
<li aria-haspopup="true" class="ui-menu-item" id="ui-id-11" tabindex="-1" role="menuitem"><span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>Delphi
<ul class="ui-menu ui-widget ui-widget-content ui-front" role="menu" aria-expanded="false" style="display: none; top: -1px; left: 150px;" aria-hidden="true">
<li class="ui-menu-item" id="ui-id-12" tabindex="-1" role="menuitem">Ada</li>
<li class="ui-menu-item" id="ui-id-13" tabindex="-1" role="menuitem">Saarland</li>
<li class="ui-menu-item" id="ui-id-14" tabindex="-1" role="menuitem">Salzburg</li>
</ul>
</li>
<li aria-haspopup="true" class="ui-menu-item" id="ui-id-15" tabindex="-1" role="menuitem"><span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>Delphi
<ul class="ui-menu ui-widget ui-widget-content ui-front" role="menu" aria-hidden="true" aria-expanded="false" style="display: none;">
<li class="ui-menu-item" id="ui-id-16" tabindex="-1" role="menuitem">Ada</li>
<li class="ui-menu-item" id="ui-id-17" tabindex="-1" role="menuitem">Saarland</li>
<li class="ui-menu-item" id="ui-id-18" tabindex="-1" role="menuitem">Salzburg</li>
</ul>
</li>
<li class="ui-menu-item" id="ui-id-19" tabindex="-1" role="menuitem">Perch</li>
</ul>
</li>
<li class="ui-state-disabled ui-menu-item" id="ui-id-20" tabindex="-1" role="menuitem" aria-disabled="true">Amesville</li>
</ul>
</body>

Code
// find all items
WebElement menu = driver.findElement(By.id("menu"));
List<WebElement> listItems = menu.findElements(By.className("ui-menu-item"));
for(WebElement listItem : listItems) {
    // logic
    // if item is menu, start new loop
    //       else - check it its requested item
}
« Last Edit: February 15, 2016, 14:47:29 pm by Sebastian »

 

Sitemap 1 2 3 4 5 6 7 8