Package uk.co.evoco.webdriver.utils
Class JavaScriptUtils
- java.lang.Object
-
- uk.co.evoco.webdriver.utils.JavaScriptUtils
-
public final class JavaScriptUtils extends 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 void
executeFile(org.openqa.selenium.WebDriver webDriver, String filename)
Reads a file from the classpath (./src/test/resources/javascript/myfile.js) and executes it via the JavaScript executor.static void
executeString(org.openqa.selenium.WebDriver webDriver, String javascript)
Executes a given JavaScript scriptstatic void
executeString(org.openqa.selenium.WebDriver webDriver, org.openqa.selenium.WebElement webElement, String javascript)
Executes a given JavaScript script against a given WebElement
-
-
-
Method Detail
-
executeString
public static void executeString(org.openqa.selenium.WebDriver webDriver, 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, 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, String filename) throws IOException
Reads 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:
IOException
- if the file cannot be found
-
-