code: public <R> R doInCurrentContext(Function<SearchContext, ? extends R> function) {
          try {
              return function.apply(getCurrentContext());
          } catch (WebDriverException e) {
              if (isStaleElementException(e)) {
                  // current context was no good to search in
                  currentContextIsStale = true;
                  // by getting the context we trigger explicit exception
                  getCurrentContext();
              }
              throw e;
          }
      }
docs: Perform action/supplier in current context.
  @param function function to perform.
  @param <R> type of result.
  @return function result.
  @throws StaleContextException if function threw stale element exception (i.e. current context could not be used)