title: how can i click the button if the xpath has changed somehow
body: <p>here is the code:
  Gen_enemy = driver.find_element_by_class_name('kt-callout__action')</p>
  <pre><code>for i in range(5):
  
      time.sleep(y)
  
      Gen_enemy.click()
  
      time.sleep(y)
  
      driver.find_element_by_xpath('/html/body/div[6]/div/div[3]/button[1]').click()
  
      time.sleep(b)
  
      driver.find_element_by_xpath('/html/body/div[6]/div/div[3]/button[1]').click()
  
      time.sleep(y)
      driver.find_element_by_xpath('//*[@id=&quot;attackButton&quot;]').click()
      inBattle = True
  
      while inBattle == True:
  
          time.sleep(Q)
  
          try:
              time.sleep(a)
  
              Rewards = driver.find_element_by_xpath('/html/body/div[6]/div/div[3]/button[1]')
              Rewards.click()
  
              time.sleep(a)
  
              driver.find_element_by_css_selector('#success-killed &gt; div.alert-text &gt; div &gt; a').click()
  
              time.sleep(b)
  
              inBattle = False
  
  
          except :
              driver.find_element_by_xpath('//*[@id=&quot;attackButton&quot;]').click()
  </code></pre>
  <p>The Error:
  selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document</p>