title: Java Selenium testing, can we get javaScript variables to assert
body: <p>I want to test a front end vanilla javascript using Selenium in java. I can easily open the page click on some stuff etc, but I couldn't figure out exactly what is the best practices to assert tests. Mainly, can we get the variables after clicking on some buttons, for example let's say:</p>
  <pre><code>function button(){
    variable = 2;
  }
  </code></pre>
  <p>Let's say some button calls the function above, in selenium I can click on the function but is there a way to call the variable and do something like;</p>
  <pre><code>AssertEquals(2, driver.getVariableFromJavascriptAfterClick())
  </code></pre>
  <p>If not, how should I test something like that.</p>
  <p>Thanks</p>