How to identify java script variable change in selenium C#



  • As on the below I’m having a HTML page where it change the variable value at the run time.

    So the java script is to change the isrendered variable to true after 10 seconds. Even after I inspect the HTML page source the original isrendered variable stays as false. That means it’s not actually changing the page source. But somehow after 10 seconds system identifies isrendered as true.

    So is there any way to capture something like this using selenium.

    <div class="full-height">
      Hello !
    </div>
    
    <script>
        var isrendered=false;
    
      setTimeout(function(){ isrendered =true; }, 10000);
    
    </script>
    



  • I was able to read the variable name bu below code.

    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    string result = js.ExecuteScript("return isrendered").ToString();
    

    So the code will be

    public static void CheckForString()
    {
        IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
        string result = js.ExecuteScript("return isrendered").ToString();
    
        if (result =="False")
        {
            Thread.Sleep(5000);
            CheckForString();
        }
        else
        {
            //
        }
    }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2