Locating a child of a child in Selenium (Python)
<p>I'm trying to locate two input fields on an unordered menu list, but Selenium is unable to find them. So far I've attempted to locate them by xpath and class name with an ordinal identifier </p>

<pre><code>("//input[@class=x-form-text x-form-field][4]")
</code></pre>

<p>but it either doesn't locate the element or it says it is improperly formatted.  The only success I've had is if I use the id, but the number on the end changes every time the page loads.</p>

<p>Is there any way to have it locate the menu list, then the list item, and then the input field?  I am totally stumped.</p>

<p>Notes about the menu list:  It changes size based on resolution and if it becomes much smaller a down arrow icon will appear and the fields towards the bottom of the list will disappear unless that down button is selected.</p>

<p>Here's an example of the html:</p>

<pre><code>&lt;ul id="ext-gen406" class="x-menu-list"&gt;
    &lt;li id="ext-comp-1237" class="list-item "&gt;
    &lt;li id="ext-comp-1238" class="list-item "&gt;
    &lt;li id="ext-comp-1239" class="list-item "&gt;
    &lt;li id="ext-comp-1240" class="list-item "&gt;
    &lt;li id="ext-comp-1241" class="list-item "&gt;
    &lt;li id="ext-comp-1242" class="list-item "&gt;
    &lt;li id="ext-comp-1207" class="list-item sep-li"&gt;
    &lt;li id="ext-comp-1243" class="list-item "&gt;
    &lt;li id="ext-comp-1244" class="list-item "&gt;
    &lt;li id="ext-comp-1208" class="list-item sep-li"&gt;
    &lt;li id="ext-comp-1245" class="list-item "&gt;
    &lt;li id="ext-comp-1246" class="list-item "&gt;
    &lt;li id="ext-comp-1247" class="list-item "&gt;
    &lt;li id="ext-comp-1248" class="list-item "&gt;
        &lt;div id="ext-gen424" class="x-form-field-wrap x-form-field-trigger-wrap"&gt;
            &lt;input id="ext-comp-1248" class="x-form-text x-form-field"name="ext-comp-1248" 
        &lt;/div&gt;
    &lt;li id="ext-comp-1249" class="list-item "&gt;
    &lt;li id="ext-comp-1250" class="list-item "&gt;
        &lt;div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen426"&gt;
             &lt;input id="ext-comp-1250" name="ext-comp-1250" class="x-form-text x-form-field" 
         &lt;/div&gt;        
    &lt;li id="ext-comp-1251" class="list-item "&gt;
    &lt;li id="ext-comp-1252" class="list-item "&gt;
&lt;/ul&gt;
</code></pre>

<blockquote>
  <p>I tried this method and for some reason it only locates the first input field. It doesn't locate any of the other input fields in the list. (There are 12). Can someone provide more information on how to use nth children?</p>
</blockquote>

<p>In this case you should try using <code>find_elements</code> to find all <code>input</code> elements and perform certain action on particular element using index below :-</p>

<pre><code>all_inputs = driver.find_elements_by_css_selector("ul.x-menu-list &gt; li.list-item input.x-form-text")
</code></pre>

<blockquote>
  <p>The two input fields that I'm trying to locate are the 9th and 10th input fields in this list. </p>
</blockquote>

<pre><code>#now use index to get desire input element 
if len(all_inputs) &gt;= 10:
  desire_input_9 = all_inputs[8]
  desire_input_10 = all_inputs[9]
</code></pre>

python selenium xpath