Python/Selenium, how to access html list without id, but has mutlitple list of same class on page
<p>I am new to Selenium and was wondering how to correctly find items in the html list below.  The issue I am having is the html list does not have an 'id' directly, it is in a 'span' a couple of lines above.  The page has a few of these an they all have the same class "selectUL".  In this example case it is the "lang" list, but there is also region, timezone etc. </p>

<p>I am trying to write a function that takes a 'field'(lang region etc) and use that to find_element_by_xpath to parse it out and eventually report which one is selected (and or another function to set the selection)</p>

<p>So...  assuming browser is webdriver.Chrome() and I was able to log in etc.</p>

<pre><code>field = "lang"
# obviously not working but hopefully concept makes sense
sysEntry = browser.find_element_by_xpath("//*[@id='{}']//ul[contains(@class, 'selectUL')]".format(field))
</code></pre>

<p>Web Page snippit looks like:</p>

<pre><code>&lt;table class="info_table conf_table" cellspacing="0" cellpadding="0"&gt;
   &lt;tr&gt;
      &lt;td class="head" colspan="2"&gt;Language / Country&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
      &lt;td class="sub_head"&gt;Language&lt;/td&gt;
      &lt;td class="content normal"&gt;
         &lt;div class="selectbox selectmenu"&gt;
            &lt;a class="selectbtn"&gt;
               &lt;span id="lang" class="selecttext"&gt;None&lt;/span&gt;
               &lt;span class="select-arrow"&gt;&lt;/span&gt;
            &lt;/a&gt;
            &lt;ul class="selectUL"&gt;
               &lt;li id="langEN" class="sel"&gt;&lt;a href="javascript:"&gt;English&lt;/a&gt;
               &lt;/li&gt;
               &lt;li id="langFR"&gt;&lt;a href="javascript:"&gt;French&lt;/a&gt;
               &lt;/li&gt;
               &lt;li id="langGE"&gt;&lt;a href="javascript:"&gt;German&lt;/a&gt;
               &lt;/li&gt;
            &lt;/ul&gt;
         &lt;/div&gt;
</code></pre>

<p>How do I access these so that I can read from/write to them?</p>

<p>I think the easier way to do this is to look for <code>class="sel"</code> on the <code>LI</code>. That seems to indicate which option is selected. From there, you can grab the <code>A</code> inside and then the text inside the <code>A</code>. You can use a CSS Selector to find this element using "li.sel > a" then grab the text inside that element. Something like</p>

<pre><code>browser.find_element_by_css_selector("li.sel &gt; a").text
</code></pre>

<p>This should return "English" from your HTML sample above.</p>

<hr>

<p>Let's go a slightly different but more specific route. We can use XPath to find the TD that contains "Language" and then down through the children from there to find the <code>LI</code> with class <code>sel</code> and then get the <code>A</code> that contains the text you want.</p>

<pre><code>browser.find_element_by_xpath("//td[@class='sub_head'][text()='Language']/following-sibling::td//li[@class='sel']/a").text
</code></pre>

python selenium-webdriver