code: public static JavascriptExecutor getJavascriptExecutor(SearchContext searchContext) {
          JavascriptExecutor executor = null;
          if (searchContext instanceof JavascriptExecutor) {
              executor = (JavascriptExecutor) searchContext;
          } else {
              if (searchContext instanceof WrapsDriver) {
                  WrapsDriver wraps = (WrapsDriver) searchContext;
                  WebDriver wrapped = wraps.getWrappedDriver();
                  if (wrapped instanceof JavascriptExecutor) {
                      executor = (JavascriptExecutor) wrapped;
                  }
              }
          }
          if (executor == null) {
              throw new IllegalArgumentException("Unable to get: " + JavascriptExecutor.class.getName()
                      + " from: " + searchContext.getClass().getName());
          }
          return executor;
      }
docs: Obtains executor based on Selenium context.
  @param searchContext context in which javascript should be executed.
  @return JavascriptExecutor based on search context.
  @throws IllegalArgumentException when no executor could be obtained from context.