<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>183278</bug_id>
          
          <creation_ts>2018-03-02 01:04:05 -0800</creation_ts>
          <short_desc>Automation: stale elements not detected when removed from the DOM</short_desc>
          <delta_ts>2018-03-05 00:29:20 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebDriver</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Garcia Campos">cgarcia</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bburg</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1403172</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2018-03-02 01:04:05 -0800</bug_when>
    <thetext>We detect stale elements when the page is reloaded because the maps are recreated, but if an element is removed from the DOM for the same document we keep the nodes in the maps. We should clear stale elements before accessing the maps. This causes test imported/selenium/py/test/selenium/webdriver/common/webdriverwait_tests.py::testExpectedConditionStalenessOf to fail.

________________________________________________________________________ testExpectedConditionStalenessOf[WebKitGTK] _________________________________________________________________________

driver = &lt;selenium.webdriver.webkitgtk.webdriver.WebDriver (session=&quot;2b612d84-8003-49e2-9fa6-6629e446a25f&quot;)&gt;, pages = &lt;conftest.Pages object at 0x7f731a9e8190&gt;

    def testExpectedConditionStalenessOf(driver, pages):
        pages.load(&apos;dynamicallyModifiedPage.html&apos;)
        element = driver.find_element_by_id(&apos;element-to-remove&apos;)
        with pytest.raises(TimeoutException):
            WebDriverWait(driver, 0.7).until(EC.staleness_of(element))
        driver.find_element_by_id(&apos;buttonDelete&apos;).click()
        assert &apos;element&apos; == element.text
&gt;       WebDriverWait(driver, 0.7).until(EC.staleness_of(element))

driver     = &lt;selenium.webdriver.webkitgtk.webdriver.WebDriver (session=&quot;2b612d84-8003-49e2-9fa6-6629e446a25f&quot;)&gt;
element    = &lt;selenium.webdriver.remote.webelement.WebElement (session=&quot;2b612d84-8003-49e2-9fa6-6629e446a25f&quot;, element=&quot;node-3C1BAE7B-915C-4AFD-995D-A1A92E529ECC&quot;)&gt;
pages      = &lt;conftest.Pages object at 0x7f731a9e8190&gt;

WebDriverTests/imported/selenium/py/test/selenium/webdriver/common/webdriverwait_tests.py:254: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;selenium.webdriver.support.wait.WebDriverWait (session=&quot;2b612d84-8003-49e2-9fa6-6629e446a25f&quot;)&gt;
method = &lt;selenium.webdriver.support.expected_conditions.staleness_of object at 0x7f731a9e8790&gt;, message = &apos;&apos;

    def until(self, method, message=&apos;&apos;):
        &quot;&quot;&quot;Calls the method provided with the driver as an argument until the \
            return value is not False.&quot;&quot;&quot;
        screen = None
        stacktrace = None
    
        end_time = time.time() + self._timeout
        while True:
            try:
                value = method(self._driver)
                if value:
                    return value
            except self._ignored_exceptions as exc:
                screen = getattr(exc, &apos;screen&apos;, None)
                stacktrace = getattr(exc, &apos;stacktrace&apos;, None)
            time.sleep(self._poll)
            if time.time() &gt; end_time:
                break
&gt;       raise TimeoutException(message, screen, stacktrace)
E       TimeoutException: Message:

end_time   = 1519977653.752561
message    = &apos;&apos;
method     = &lt;selenium.webdriver.support.expected_conditions.staleness_of object at 0x7f731a9e8790&gt;
screen     = None
self       = &lt;selenium.webdriver.support.wait.WebDriverWait (session=&quot;2b612d84-8003-49e2-9fa6-6629e446a25f&quot;)&gt;
stacktrace = None
value      = False

WebDriverTests/imported/selenium/py/selenium/webdriver/support/wait.py:80: TimeoutException</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1403173</commentid>
    <comment_count>1</comment_count>
      <attachid>334885</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2018-03-02 01:06:59 -0800</bug_when>
    <thetext>Created attachment 334885
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1403297</commentid>
    <comment_count>2</comment_count>
      <attachid>334885</attachid>
    <who name="Blaze Burg">bburg</who>
    <bug_when>2018-03-02 10:44:08 -0800</bug_when>
    <thetext>Comment on attachment 334885
Patch

I hope we don&apos;t have 1000&apos;s of nodes or this could get expensive. It would be nice to just check the validity of the requested node, but I guess any node could be requested via script. We&apos;d have to find the web elements after transforming JS payload to elements.

Let&apos;s just keep this version unless we think it&apos;s actually causing a performance problem. I like simple and brute force when we can get away with it.

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1403526</commentid>
    <comment_count>3</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2018-03-04 02:24:26 -0800</bug_when>
    <thetext>(In reply to Brian Burg from comment #2)
&gt; Comment on attachment 334885 [details]
&gt; Patch
&gt; 
&gt; I hope we don&apos;t have 1000&apos;s of nodes or this could get expensive. It would
&gt; be nice to just check the validity of the requested node, but I guess any
&gt; node could be requested via script. We&apos;d have to find the web elements after
&gt; transforming JS payload to elements.

I started the patch by only checking the requested node indeed. But then I realized that the node can be queried multiple times, so we could be checking more than once. Then I thought, let&apos;s see what chromium does, and they also clear the cache on every execute_script call, so I decided to do the same.

&gt; Let&apos;s just keep this version unless we think it&apos;s actually causing a
&gt; performance problem. I like simple and brute force when we can get away with
&gt; it.

Ok.

&gt; r=me

Thanks</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1403571</commentid>
    <comment_count>4</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2018-03-05 00:28:54 -0800</bug_when>
    <thetext>Committed r229210: &lt;https://trac.webkit.org/changeset/229210&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1403572</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-03-05 00:29:20 -0800</bug_when>
    <thetext>&lt;rdar://problem/38132475&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>334885</attachid>
            <date>2018-03-02 01:06:59 -0800</date>
            <delta_ts>2018-03-02 10:44:08 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>wd-stale-elements.diff</filename>
            <type>text/plain</type>
            <size>2665</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nIGIvU291cmNlL1dlYktpdC9DaGFu
Z2VMb2cKaW5kZXggYTNmNjIwZmI2NmMuLjJiOTI0ODAxOTM2IDEwMDY0NAotLS0gYS9Tb3VyY2Uv
V2ViS2l0L0NoYW5nZUxvZworKysgYi9Tb3VyY2UvV2ViS2l0L0NoYW5nZUxvZwpAQCAtMSwzICsx
LDIyIEBACisyMDE4LTAzLTAyICBDYXJsb3MgR2FyY2lhIENhbXBvcyAgPGNnYXJjaWFAaWdhbGlh
LmNvbT4KKworICAgICAgICBB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2xlYXJTdGFsZU5vZGVzKCk7CisKICAgICAgICAgbGV0IGFy
Z3VtZW50VmFsdWVzID0gYXJndW1lbnRTdHJpbmdzLm1hcCh0aGlzLl9qc29uUGFyc2UsIHRoaXMp
OwogCiAgICAgICAgIGxldCB0aW1lb3V0SWRlbnRpZmllciA9IDA7CkBAIC03MCw2ICs3Miw3IEBA
IGxldCBBdXRvbWF0aW9uU2Vzc2lvblByb3h5ID0gY2xhc3MgQXV0b21hdGlvblNlc3Npb25Qcm94
eQogCiAgICAgbm9kZUZvcklkZW50aWZpZXIoaWRlbnRpZmllcikKICAgICB7CisgICAgICAgIHRo
aXMuX2NsZWFyU3RhbGVOb2RlcygpOwogICAgICAgICB0cnkgewogICAgICAgICAgICAgcmV0dXJu
IHRoaXMuX25vZGVGb3JJZGVudGlmaWVyKGlkZW50aWZpZXIpOwogICAgICAgICB9IGNhdGNoIChl
cnJvcikgewpAQCAtMTM1LDYgKzEzOCwxNiBAQCBsZXQgQXV0b21hdGlvblNlc3Npb25Qcm94eSA9
IGNsYXNzIEF1dG9tYXRpb25TZXNzaW9uUHJveHkKIAogICAgICAgICByZXR1cm4gaWRlbnRpZmll
cjsKICAgICB9CisKKyAgICBfY2xlYXJTdGFsZU5vZGVzKCkKKyAgICB7CisgICAgICAgIGZvciAo
dmFyIFtub2RlLCBpZGVudGlmaWVyXSBvZiB0aGlzLl9ub2RlVG9JZE1hcCkgeworICAgICAgICAg
ICAgaWYgKCFkb2N1bWVudC5jb250YWlucyhub2RlKSkgeworICAgICAgICAgICAgICAgIHRoaXMu
X25vZGVUb0lkTWFwLmRlbGV0ZShub2RlKTsKKyAgICAgICAgICAgICAgICB0aGlzLl9pZFRvTm9k
ZU1hcC5kZWxldGUoaWRlbnRpZmllcik7CisgICAgICAgICAgICB9CisgICAgICAgIH0KKyAgICB9
CiB9OwogCiByZXR1cm4gbmV3IEF1dG9tYXRpb25TZXNzaW9uUHJveHk7Cg==
</data>
<flag name="review"
          id="353591"
          type_id="1"
          status="+"
          setter="bburg"
    />
          </attachment>
      

    </bug>

</bugzilla>