Matt Brennan Matt Brennan - 7 months ago 68
HTML Question

How to locate indistinct list items with xpath for Selenium IDE?

I'm trying to set up some automated test cases with WebDriver, using Selenium IDE with FireBug to get a good idea of what I'm doing. I've got it mostly figured out except for one major thing. This element

<div class="select2-drop select2-display-none select2-with-searchbox select2-drop-active select2-drop-above" style="left: 1200.5px; width: 438px; top: auto; bottom: 152px; display: block;" id="select2-drop">

opens a dropdown menu full of list items. EVERY item has the same id and class, set as a list item. Example:

<li class="select2-results-dept-0 select2-result select2-result-selectable">
<div class="select2-result-label">
<span class="select2-match"></span>

The only difference between each list item is what's located inside the div tags, right after the span tags.

How do I differ each of these from the other using Selenium IDE? It won't record anything selected in the drop-down menu, or the drop-down itself. I've worked around clicking the drop-down with manually submitting the code. How would I find each element's Xpath, and translate that into a click command for WebDriver?


use xpath that finds element with its text.