title: python selenium cannot find the right object. How to determine the right frame?
body: <p>I do a very short recording with Selenium IDE this is the IDE generate code:</p>
  <pre><code>import pytest
  import time
  import json
  from selenium import webdriver
  from selenium.webdriver.common.by import By
  from selenium.webdriver.common.action_chains import ActionChains
  from selenium.webdriver.support import expected_conditions
  from selenium.webdriver.support.wait import WebDriverWait
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  
  class TestProv():
    def setup_method(self, method):
      self.driver = webdriver.Firefox()
      self.vars = {}
    
    def teardown_method(self, method):
      self.driver.quit()
    
    def test_prov(self):
      self.driver.get(&quot;https://portal.ppp.us/hrj/pstrtal&quot;)
      self.driver.set_window_size(1144, 699)
      self.driver.find_element(By.ID, &quot;def&quot;).click()
      self.driver.find_element(By.ID, &quot;def&quot;).send_keys(&quot;Usr&quot;)
      self.driver.find_element(By.ID, &quot;logonpassfield&quot;).click()
      self.driver.find_element(By.ID, &quot;logonpassfield&quot;).send_keys(&quot;Pwd&quot;)
      self.driver.find_element(By.ID, &quot;button&quot;).click()
      self.driver.find_element(By.LINK_TEXT, &quot;Løn- og Personaleoplysninger&quot;).click()
      element = self.driver.find_element(By.LINK_TEXT, &quot;Løn- og Personaleoplysninger&quot;)
      actions = ActionChains(self.driver)
      actions.move_to_element(element).perform()
      element = self.driver.find_element(By.LINK_TEXT, &quot;Løn- og Personaleoplysninger&quot;)
      actions = ActionChains(self.driver)
      actions.move_to_element(element).perform()
      element = self.driver.find_element(By.CSS_SELECTOR, &quot;body&quot;)
      actions = ActionChains(self.driver)
      actions.move_to_element(element, 0, 0).perform()
      self.driver.switch_to.frame(3)
      self.driver.switch_to.frame(2)
      self.driver.find_element(By.ID, &quot;htmlb_417198_htmlb_144219_1&quot;).click()
      self.driver.find_element(By.ID, &quot;htmlb_417198_htmlb_144219_1&quot;).send_keys(&quot;03-07-2020&quot;)
      self.driver.find_element(By.ID, &quot;htmlb_417198_htmlb_144219_7&quot;).click()
  </code></pre>
  <p>The problem I have is in the last 5 lines. the ID htmlb_417198_htmlb_144219_1 changes for every time the numbers are different however the structure is the same so I search the object with:</p>
  <pre><code>browser.find_elements_by_xpath(&quot;//*[substring(@id, 1, 6) = 'htmlb_' and substring(@id, string-length(@id) - 1) = '_1']&quot;) 
  </code></pre>
  <p>which finds objects with the above structure.</p>
  <p>However it finds among many others the field:</p>
  <pre><code>htmlb_417198_htmlb_1442**21**_1
  </code></pre>
  <p>while the IDE recorder registered a slightly different ID (we speak of the same session):</p>
  <pre><code>htmlb_417198_htmlb_1442**19**_1
  </code></pre>
  <p>I simply cannot find the field I am looking for (which I clearly can see with an inspect with the correct ID). So I am not catching the right object with my statement, it seems like I am in a different frame since the object IDE recorded is not at all in the frame. I execute  the search in all frames, the only frame that returns something is</p>
  <pre><code>browser.switch_to.default_content()
  </code></pre>
  <p>all other frames either return an error &quot;frame nonexistent&quot; or do not return the right object:</p>
  <pre><code>browser.switch_to.frame(0)
  browser.switch_to.frame(1)
  browser.switch_to.frame(2)
  browser.switch_to.frame(3)
  ....
  </code></pre>
  <p>I really don't understand why Selenium IDE records:</p>
  <pre><code>self.driver.switch_to.frame(3)
  self.driver.switch_to.frame(2)
  </code></pre>
  <p>I have recorded several times and it returns the same code</p>
  <p><strong>Knowing the ID, is there a way to search in the whole website and retrieve the frame # it is located in?</strong></p>