A cheat sheet of common WebDriverBiDi.NET commands and patterns.
Driver Lifecycle
Operation
Code
Create driver
BiDiDriver driver = new BiDiDriver(TimeSpan.FromSeconds(30));
Start connection
await driver.StartAsync("ws://localhost:9515/session/YOUR-SESSION-ID"); (the webSocketUrl from a chromedriver/geckodriver session; see Browser Setup)
Check if started
bool isStarted = driver.IsStarted;
Stop connection
await driver.StopAsync();
Dispose
await driver.DisposeAsync();
Session
Operation
Code
Check status
await driver.Session.StatusAsync();
Subscribe to events
SubscribeCommandParameters sub = new SubscribeCommandParameters(driver.Network.OnBeforeRequestSent.EventName); await driver.Session.SubscribeAsync(sub);
End session
await driver.Session.EndAsync();
Browsing Context
Operation
Code
Get context tree
GetTreeCommandResult tree = await driver.BrowsingContext.GetTreeAsync();
ProvideResponseCommandParameters p = new ProvideResponseCommandParameters(requestId) { Body = BytesValue.FromString(body) }; await driver.Network.ProvideResponseAsync(p);
Storage
Operation
Code
Get cookies
GetCookiesCommandParameters p = new GetCookiesCommandParameters(); p.Partition = new BrowsingContextPartitionDescriptor(contextId); GetCookiesCommandResult r = await driver.Storage.GetCookiesAsync(p);
DeleteCookiesCommandParameters p = new DeleteCookiesCommandParameters(); p.Partition = new BrowsingContextPartitionDescriptor(contextId); await driver.Storage.DeleteCookiesAsync(p);
Input
Operation
Code
Perform actions
PerformActionsCommandParameters p = new PerformActionsCommandParameters(contextId); PointerSourceActions mouse = new PointerSourceActions(); mouse.Actions.Add(new PointerMoveAction { X = 100, Y = 100 }); p.Actions.Add(mouse); await driver.Input.PerformActionsAsync(p);