We will learn about “executeScript ” method in this post.
java.lang.Object executeScript(java.lang.String script,java.lang.Object… args)
What is meant by “The script fragment provided will be executed as the body of an anonymous function.”?
It means, if we write as below:
Arguments to method executeScript :
executeScript method takes two arguments:
Let’s understand this by an example:
Return type of method executeScript :
If the script has a return value (i.e. if the script contains a
return statement), then the following steps will be taken:
- For an HTML element, this method returns a WebElement
- For a decimal, a Double is returned
- For a non-decimal number, a Long is returned
- For a boolean, a Boolean is returned
- For all other cases, a String is returned.
- For an array, return a List<Object> with each object following the rules above. We support nested lists.
- For a map, return a Map<String, Object> with values following the rules above.
- Unless the value is null or there is no return value, in which null is returned
You can see output as “false” which is returned by executeScript method and we have printed it on console.
Hope you will have clear understanding of method executeScript.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
Author: Amod Mahajan
A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.