code: public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchContext) {
          if (searchContext instanceof WebDriver) {
              return (WebDriver) searchContext;
          }
  
          if (searchContext instanceof WrapsDriver) {
              return unpackWebDriverFromSearchContext(
                      ((WrapsDriver) searchContext).getWrappedDriver());
          }
  
          // Search context it is not only Webdriver. Webelement is search context too.
          // RemoteWebElement and MobileElement implement WrapsDriver
          if (searchContext instanceof WrapsElement) {
              return unpackWebDriverFromSearchContext(
                      ((WrapsElement) searchContext).getWrappedElement());
          }
  
          return null;
      }
docs: This method extract an instance of {@link WebDriver} from the given {@link SearchContext}.
  @param searchContext is an instance of {@link SearchContext}. It may be the instance of
  {@link WebDriver} or {@link org.openqa.selenium.WebElement} or some other
  user's extension/implementation.
  Note: if you want to use your own implementation then it should implement
  {@link WrapsDriver} or {@link WrapsElement}
  @return the instance of {@link WebDriver}.
  Note: if the given {@link SearchContext} is not
  {@link WebDriver} and it doesn't implement
  {@link WrapsDriver} or {@link WrapsElement} then this method returns null.