0

I am initializing ChromeDriver on selenium grid using RemoteWebdriver, then I need to cast RemoteWebDriver to ChromeDriver?

If it is possible, can I have an example?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
praveen h
  • 39
  • 1
  • 3

4 Answers4

1

ChromeDriver is the extension of RemoteWebDriver. If the actual object that is referred by RemoteWebDriver is a ChromeDriver you can use explicit casting.

Otherwise you will fail to cast since under RemoteWebDriver some other extension might take the place (for example FirefoxDriver also can be refered as RemoteWebDriver) which might not adhere the contract ChromeDriver implies (the same is applicable to a pure RemoteWebDriver - the object simply does not contain the part that is specific for ChromeDriver).

Alexey R.
  • 8,057
  • 2
  • 11
  • 27
1

Till Selenium v3, ChromeDriver extends RemoteDriver. This ChromeDriver was a WebDriver implementation that controled the browser running on the local machine.

However, unleashes a new design/feature where,

  • ChomeDriver extends to ChromiumDriver and
  • ChromiumDriver extends RemoteDriver

As an example to intercept the Network you can do the following:

System.setProperty("webdriver.chrome.driver","C:\\WebDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
ChromeDriver driver = new ChromeDriver(options);
DevTools devTool = driver.getDevTools();
devTool.createSession();
devTool.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
devTool.send(Network.setBlockedURLs(ImmutableList.of("*.jpg", "*.jpeg", "*.png", "*.css")));
driver.get("https://amazon.in/b?node=1375424031");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

We have not need to cast Drivers, we have only need to initialise the WebDriver variable it can handle all the different type of driver.

WebDriver driver = null;
if (grid)
    driver = new RemoteWebDriver(new URL("localhost:4444"));
else
    driver = new ChromeDriver();
0

You have to use Augmenter mechanism for instance DevTools

Marious
  • 143
  • 1
  • 11