How to select list item with dynamically generated ids - Selenium test Python
<p>I have a problem here where I am unable to locate the list items. </p>

<pre><code>&lt;ul id="select2-id_faculty_advisor-results" class="select2-results__options" role="tree" aria-multiselectable="true" aria-expanded="true" aria-hidden="false"&gt;
    &lt;li id="select2-id_faculty_advisor-result-0pu4-1" class="select2-results__option select2-results__option--highlighted" role="treeitem" aria-selected="true"&gt;Alice&lt;/li&gt;
    &lt;li id="select2-id_faculty_advisor-result-cayw-2" class="select2-results__option" role="treeitem" aria-selected="false"&gt;Bob&lt;/li&gt;
    &lt;li id="select2-id_faculty_advisor-result-4h8e-3" class="select2-results__option" role="treeitem" aria-selected="false"&gt;Candy&lt;/li&gt;
    &lt;li id="select2-id_faculty_advisor-result-el4l-4" class="select2-results__option" role="treeitem" aria-selected="false"&gt;Dark&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>As seen above I'll not be able to find elements by id as the characters in between are generated dynamically. Any idea of how to locate a particular element??</p>

<p>the best way to do it make collection of list by xpath "//ul[@id='select2-id_faculty_advisor-results']/li"</p>

<p>after that you can select them by index from the collection.</p>

python selenium selenium-webdriver