title: How to get an element after it has changed in selenium?
body: <p>I have pages with ads that display phone numbers after clicking on an item, but all these pages can have different formats and iterate over them all for a very long time. <a href="https://www.work.ua/ru/jobs/3385738/" rel="nofollow noreferrer">Page example.</a></p>
  
  <p>I try to find a clickable element on the page, save it and the parent element, click on the element and then find it through the parent element, but I can’t do it:</p>
  
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; phone = driver.find_element_by_xpath('.//a[contains(@class, "link-phone")]')
  &gt;&gt;&gt; phone.get_attribute('innerHTML')
  '\n                    &lt;span class="glyphicon glyphicon-phone"&gt;&lt;/span&gt;Показать телефон'
  &gt;&gt;&gt; phone_elem = phone.find_element_by_xpath('..')
  &gt;&gt;&gt; phone_elem.get_attribute('innerHTML')
  '&lt;a class="link-phone nowrap js-get-phone" href="javascript:void(0);"&gt;\n                    &lt;span class="glyphicon glyphicon-phone"&gt;&lt;/span&gt;Показать телефон&lt;/a&gt; '
  &gt;&gt;&gt; ActionChains(driver).move_to_element(phone).perform()
  &gt;&gt;&gt; sleep(0.5)
  &gt;&gt;&gt; phone.click()
  &gt;&gt;&gt; sleep(1.5)
  &gt;&gt;&gt; phone_elem.get_attribute('innerHTML')
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 141, in get_attribute
      self, name)
    File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in execute_script
      'args': converted_args})['value']
    File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
      self.error_handler.check_response(response)
    File "C:\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
      raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
    (Session info: chrome=79.0.3945.56)
  
  &gt;&gt;&gt;                                                                                                                                                                                              
  </code></pre>
  
  <p>Most likely, after clicking on an element the whole page changes. What can I do?</p>