title: How to match xpath for id element that changes each time page loads?
body: <p>I have these 2 xpath that are different each time I load a webpage. </p>
  
  <p>The xpaths were recorded by Selenium-IDE and always have <code>mainForm_view</code> within the id string and the text before and after this always changes.</p>
  
  <pre><code>xpath=//input[@id='abc_hyd_wuu2_8333nd_mainForm_view_jjd_uueue2_jjd_11_jkdhd']
  xpath=//div[@id='abc_hyd_wuu2_8333nd_mainForm_view_kcjjcs_sjsjs_jjdj_994_kkk']/div/div[2]/div/div/div/a[1]/h2
  </code></pre>
  
  <p>I've tried to locate the id like below but doesn't work.</p>
  
  <pre><code>xpath=//input[contains(@id,'mainForm_view')]
  xpath=//div[contains(@id,'mainForm_view')]
  </code></pre>
  
  <p>Which would be the correct way to do it?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've tried with CSS selector like below but it seems is taking another <code>id</code> that is within an <code>input</code> element</p>
  
  <pre><code>document.querySelector("input[id*='mainForm_view']").id
  </code></pre>
  
  <p>Examining the html code I see that the <code>id</code> I need is related with a unique <code>class</code>. The code is like below:</p>
  
  <pre><code>  &lt;div class="Class_p2"&gt;
       &lt;div class="Class_p3" style="..."&gt;
          &lt;input name="8333nd$mainForm$view$jjd$uueue2" type="text" class="class a1 n1-Control" value="xyz" id="8333nd_mainForm_view_jjd_uueue2" disabled="disabled" style=".."&gt;
       &lt;/div&gt;
       &lt;input name="8333nd$mainForm$view$ttyi" type="text" disabled="disabled"&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>I've tried the following Javascript code in Chrome console but it doesn't work</p>
  
  <pre><code>document.getElementsByClassName("class a1 n1-Control").id
  </code></pre>
  
  <p>How would be to get the <code>id=8333nd_mainForm_view_jjd_uueue2</code> that is related with <code>Class=class a1 n1-Control</code>?</p>
  
  <p><strong>UPDATE2</strong></p>
  
  <p>I was finally able to do it with</p>
  
  <pre><code>document.getElementsByClassName("class a1 n1-Control")[0].id
  </code></pre>
  
  <p>Thanks for all the help and time.</p>