Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Java Selenium testing, can we get javaScript variables to assert

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:

function button(){
  variable = 2;
}

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;

AssertEquals(2, driver.getVariableFromJavascriptAfterClick())

If not, how should I test something like that.

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like all you need to do is

JavascriptExecutor js = (JavascriptExecutor) driver;
int val = js.executeScript("return button();");
AssertEquals(2, val);

For more details see this reference

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!