Why we do Up-casting browser driver class object to Webdriver but why we are not up-casting into SearchContext or RemoteWebDriver?

You might have seen statement like this where we are doing upcasting:

WebDriver driver = new ChromeDriver();

In above statement by a single driver, we can launch any browser. From the good programming, viewpoint its always a good practice to up-cast the object up to maximum level but keeping one thing in mind that we are not losing any important functionalities.

If we up-cast to SearchContext which has only two methods findElement() and findElements(). So if we try to access other important methods, then we need to down-casting.

Because of that, we are Up-casting up to WebDriver only so that we do not face any problems in access the important methods.