<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: DemoDev95</title>
    <description>The latest articles on DEV Community by DemoDev95 (@demodev).</description>
    <link>https://dev.to/demodev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F682077%2Fe229a01b-d055-4dcf-b883-680ddcfc755a.jpg</url>
      <title>DEV Community: DemoDev95</title>
      <link>https://dev.to/demodev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/demodev"/>
    <language>en</language>
    <item>
      <title>Why does the action swap in array when clicking after typing in javascript?</title>
      <dc:creator>DemoDev95</dc:creator>
      <pubDate>Mon, 01 Aug 2022 09:06:53 +0000</pubDate>
      <link>https://dev.to/demodev/why-does-the-action-swap-in-array-when-clicking-after-typing-in-javascript-kli</link>
      <guid>https://dev.to/demodev/why-does-the-action-swap-in-array-when-clicking-after-typing-in-javascript-kli</guid>
      <description>&lt;p&gt;I've created a chrome extension to capture the elements in the DOM according to the click order. The XPath obtained there is pushed to an array as follows. The function that performs it is as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var actionArray = [];
        function Capture(json) {

            var lastCaptureStep = actionArray[actionArray.length-1];
            if(lastCaptureStep &amp;amp;&amp;amp; lastCaptureStep.activity=="CLICK" &amp;amp;&amp;amp; lastCaptureStep.timestamp+100&amp;gt;json.timestamp){
                actionArray[actionArray.length-1] = json;
                actionArray.push(lastCaptureStep);
            }else{
                 actionArray.push(json);
            }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The received JSON is as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    {
        "activity": "TYPE",
        "xpath": "//input[@id='password']",
        "value": "Password",
        "frames": [],
        "timestamp": 1658992410657
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But in the following scenario, when the password is typed in the login screen and the remember me button is clicked, the two actions are swapped as remember me click first and type action after that. (for more details please see the image).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--40yC45pQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eiffn1cjy32isooh5yil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--40yC45pQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eiffn1cjy32isooh5yil.png" alt="Swapped Array" width="880" height="88"&gt;&lt;/a&gt;&lt;br&gt;
What is the reason for this? Is there a problem with the logic in my function?&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
