DotNetBrowser is compatible with Selenium WebDriver. To use Selenium with DotNetBrowser perform the following steps:


1. Download ChromeDriver and extract it somewhere

2. Run DotNetBrowser with the --remote-debugging-port switcher as shown in the Remote Debugging article.

3. Create Selenium WebDriver and use the remote debugging port (9222) from the previous step to connect to DotNetBrowser.


Example (Connecting from Java)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.io.File;
import java.io.IOException;

/**
* This class demonstrates how to create Selenium WebDriver and connect to the 
Chromium remote debugging server
*/
public class SeleniumSample {
    public static void main(String[] args) throws IOException {
        // Create ChromeDriverService that allows you to run ChromeDriver and start it.
        ChromeDriverService service = new ChromeDriverService.Builder()
             .usingDriverExecutable(new File("path/to/my/chromedriver"))
             .usingAnyFreePort()
             .build();
        service.start();

        DesiredCapabilities capabilities = new DesiredCapabilities();
        ChromeOptions options = new ChromeOptions();

        // The address string should be in the form of "hostname/ip:port". 9222 is the port
        // that you specified in the --remote-debugging-port Chromium switcher before starting 
        // DotNetBrowser.
        String remoteDebuggingAddress = "localhost:9222";

        // Set the address to the appropriate ChromeOption option and apply it to 
        // the DesiredCapabilities.
        // The full list of these options you can find at
        // https://sites.google.com/a/chromium.org/chromedriver/capabilities
        options.setExperimentalOption("debuggerAddress", remoteDebuggingAddress);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);

        // Create a WebDriver instance using URL provided by the ChromeDriverService
        // and capabilities with DotNetBrowser remote debugging address.
        WebDriver driver = new RemoteWebDriver(service.getUrl(), capabilities);

        // Now you can use WebDriver.
        System.out.println(driver.getCurrentUrl());
        driver.get("http://google.com");
        // Quit from the current session to prevent Chromium remote debugging server hang.
        driver.quit();
        service.stop();
    }
}