- executeScript(script, args)
- executeAsyncScript(script, args)
Let us understand this in a couple simple steps.
Import the following package,
// Scroll down by 100 pixels jsExecutor.executeScript("window.scrollBy(0,100)");
Let us see a test case implementing the technique covered so far,
- Open Firefox browser
- Navigate to the demo site (https://chandanachaitanya.github.io/selenium-practice-site/)
- Scroll the page vertically down by 100 pixels
- Refresh the page
- Navigate to the Google homepage
- Verify Eclipse IDE console output screen and JUnit pane for success result
JUnit code for this scenario is,
Comments are provided for each line of code making it self-explanatory.
In JUnit pane, the green bar shows that the test case is executed successfully. Console window shows the absence of any errors. It also shows all the printed messages as expected.
Time to experiment today’s skills. And yes, put on your safety helmets so that you don’t bump into any exceptions!
All the code files are placed in the GitHub repo for easy access. You can star and fork the repository for convenience. Please go through the ‘README.md’ file for clear instructions.
Have a great day!