title: Selenium Python I am trying to select a drop down from a nested span tag using XPATH or CSS selector
body: <p>I am trying to work out the XPATH or CSS for the drop down element which seems to be in nested span tags.
  I want to find the tag 
  I can find the text above the drop down but i cannot go down the span tags to get to the drop down element.</p>
  
  <p>I have XPATH to get to the text above the drop down.  The XPATH is:</p>
  
  <pre><code>//span[contains(text(), "Select a data preview to import configuration from")]
  </code></pre>
  
  <p>If i try to use preceding::span[2] it goes too far down.  </p>
  
  <pre><code>//span[contains(text(), "Select a data preview to import configuration from")]/preceding::span[2]
  </code></pre>
  
  <p>The HTML snippet is:</p>
  
  <pre><code>&lt;div class="GPI5XK1CM" style="padding-right: 16px;position:relative;outline:none;" __idx="0" onclick=""&gt;
  &lt;div style="position:absolute;display:none;"/&gt;
  &lt;div&gt;
  &lt;span/&gt;
  &lt;span&gt;
  &lt;span title="" style="font-weight:bold;"&gt;Select a data preview to import configuration from&lt;/span&gt;
  &lt;/span&gt;
  &lt;span/&gt;
  &lt;span&gt;
  &lt;span class="" title="" style="display:block;"/&gt;
  &lt;/span&gt;
  &lt;span/&gt;
  &lt;span/&gt;
  &lt;span/&gt;
  &lt;span/&gt;
  &lt;span/&gt;
  &lt;span&gt;
  &lt;span class="" title="None" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;"&gt;
      &lt;select tabindex="-1"&gt;
          &lt;option selected="selected" value="None"&gt;None&lt;/option&gt;
          &lt;option value="CRMINVALID_07102015"&gt;CRMINVALID_07102015&lt;/option&gt;
          &lt;option value="LADEMO_crm2_Chrome"&gt;LADEMO_crm2_Chrome&lt;/option&gt;
          &lt;option value="LADEMO_CRM_DONOTCHANGE_CHROME"&gt;LADEMO_CRM_DONOTCHANGE_CHROME&lt;/option&gt;
          &lt;option value="LADEMO_ESCR_DO_NO_CHANGE_CHROME"&gt;LADEMO_ESCR_DO_NO_CHANGE_CHROME&lt;/option&gt;
          &lt;option value="Lademo_odb_Data"&gt;Lademo_odb_Data&lt;/option&gt;
          &lt;option value="test"&gt;test&lt;/option&gt;
      &lt;/select&gt;
      &lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>What XPATH or CSS could i use to get to the drop down?  CSS is faster, that would be good.</p>
  
  <p>I think I have worked one out now but not sure if it is a good way to do it.
  This one works for me:</p>
  
  <pre><code>//span[contains(text(), "Select a data preview to import configuration from")]/preceding::span[1]//../span//../select
  </code></pre>
  
  <ul>
  <li>First search for a span element with the text Select a data preview to import configuration from</li>
  <li>then find the first span tag /preceding::span[1]</li>
  <li>then find all of the span tags below the 1st span tag //../span</li>
  <li>then find the drop down wherever it is within the span tags //../select</li>
  </ul>
  
  <p>Using //../select if the structure changes it will still work.</p>
  
  <p>Is this the correct way?</p>
  
  <p>Thanks,
  Riaz</p>