title: python selenium how to handle dynamic XPath within XPath 1.0
body: <p>I must select a field who's XPath is dynamic. In different sessions these are examples of XPath:</p>
  <pre><code>htmlb_335660_htmlb_115101_1
  htmlb_323002_htmlb_110159_1
  htmlb_331156_htmlb_111919_1
  htmlb_335204_htmlb_114985_1
  htmlb_324009_htmlb_110479_1
  htmlb_331374_htmlb_111629_1
  htmlb_331140_htmlb_112463_1
  htmlb_324978_htmlb_110752_1
  htmlb_324725_htmlb_110669_1
  htmlb_336067_htmlb_115248_1
  htmlb_324854_htmlb_110713_1
  htmlb_334552_htmlb_112898_1
  htmlb_415158_htmlb_142073_1
  </code></pre>
  <p>Here is the html code:
  </p>
  <p>This are the only 3 code snippets I can use successfully to detect the fields:</p>
  <pre><code>ids = browser.find_elements_by_xpath(&quot;//*[contains(text(), 'htmlb_') and contains(text(), 'htmlb_') and contains(text(), '_1')]&quot;)
  ids = browser.find_elements_by_xpath(&quot;//*[starts-with(text(), 'htmlb_')]&quot;)
  ids = browser.find_elements_by_xpath(&quot;//*[substring(@id, string-length(@id) - 1) = '_1']&quot;)
  for ii in ids:
      print(&quot;&gt;&quot;,ii)
  </code></pre>
  <p>All prints when I try to get an attribute (&quot;id&quot;, &quot;name&quot;, &quot;title&quot;, &quot;href&quot;, etc) give &quot;attribute not found or &quot;none&quot;. I suppose that starts-with works well and ends-with fail since ends-with is XPath 2.0 and most browsers neither Selenium supports it.</p>
  <p>So I am &quot;blindly&quot; detecting 3 fields but I cannot see more details of the fields except when I print the object as above (&quot;ii&quot;): then I get:</p>
  <pre><code>&gt; &lt;selenium.webdriver.firefox.webelement.FirefoxWebElement (session=&quot;a0779322-035d-41af-bb32-9c35973d3317&quot;, element=&quot;998d9583-79c8-4192-a078-c2d8719bbd9e&quot;)&gt;
  &gt; &lt;selenium.webdriver.firefox.webelement.FirefoxWebElement (session=&quot;a0779322-035d-41af-bb32-9c35973d3317&quot;, element=&quot;25fa3805-7794-4760-b355-1ed408472e1d&quot;)&gt;
  &gt; &lt;selenium.webdriver.firefox.webelement.FirefoxWebElement (session=&quot;a0779322-035d-41af-bb32-9c35973d3317&quot;, element=&quot;52f1ea41-3a27-4a62-8153-b38e31c1beaa&quot;)&gt;
  </code></pre>
  <p>All this statements fail:</p>
  <p>ids = browser. find_elements_by_id(&quot;id^='htmlb'&quot;)</p>
  <p>ids = browser.find_elements_by_xpath(&quot;//*[ends-with(text(), 'htmlb_')]&quot;)</p>
  <p>ids = browser.find_elements_by_id('htmlb_'+ '\d{6}' + '<em>htmlb</em>' + '\d{6}' + '_1') &lt;-- THIS ONE WOULD SOLVE MY PROBLEM!! WHY DOESN'T I WORK?</p>