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
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning