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>

<p>You can use cssSelector to solve the issue,</p>

<pre><code>driver.find_element_by_css_selector("ul.x-menu-list input.x-form-field:nth-child(1)")  //first input box
driver.find_element_by_css_selector("ul.x-menu-list input.x-form-field:nth-child(2)")  //second input box
</code></pre>

python selenium xpath