Package uk.co.evoco.webdriver.utils
Class JavaScriptUtils
java.lang.Object
uk.co.evoco.webdriver.utils.JavaScriptUtils
public final class JavaScriptUtils
extends java.lang.Object
Utilities class providing support methods for executing JavaScript
While this is straight forward, its less than obvious to newcomers.
Feel free not to use this at all and just do it with WebDriver!
-
Constructor Summary
Constructors Constructor Description JavaScriptUtils() -
Method Summary
Modifier and Type Method Description static voidexecuteFile(org.openqa.selenium.WebDriver webDriver, java.lang.String filename)Reads a file from the classpath (./src/test/resources/javascript/myfile.js) and executes it via the JavaScript executor.static voidexecuteString(org.openqa.selenium.WebDriver webDriver, java.lang.String javascript)Executes a given JavaScript scriptstatic voidexecuteString(org.openqa.selenium.WebDriver webDriver, org.openqa.selenium.WebElement webElement, java.lang.String javascript)Executes a given JavaScript script against a given WebElement
-
Constructor Details
-
JavaScriptUtils
public JavaScriptUtils()
-
-
Method Details
-
executeString
public static void executeString(org.openqa.selenium.WebDriver webDriver, java.lang.String javascript)Executes a given JavaScript script- Parameters:
webDriver- active WebDriver instancejavascript- String representing javascript expression
-
executeString
public static void executeString(org.openqa.selenium.WebDriver webDriver, org.openqa.selenium.WebElement webElement, java.lang.String javascript)Executes a given JavaScript script against a given WebElement- Parameters:
webDriver- active WebDriver instancewebElement- active WebElement, already locatedjavascript- String representing javascript expression
-
executeFile
public static void executeFile(org.openqa.selenium.WebDriver webDriver, java.lang.String filename) throws java.io.IOExceptionReads a file from the classpath (./src/test/resources/javascript/myfile.js) and executes it via the JavaScript executor. This can make tests a little more readable as there's no inline JavaScript and horrible escape characters to content with.- Parameters:
webDriver- active WebDriver instancefilename- File representing javascript expression- Throws:
java.io.IOException- if the file cannot be found
-