Click or drag to resize

WebBrowserExtensionsWaitForSelectorAsync Method

Version 102.0.100
Waits for a DOM element specified by the selector string to be added to or removed from the DOM. A simplified version of Puppeteer WaitForSelector. Uses a MutationObserver to wait for the element to become added or removed.

Namespace:  CefSharp
Assembly:  CefSharp (in CefSharp.dll) Version: (
public static Task<WaitForSelectorAsyncResponse> WaitForSelectorAsync(
	this IWebBrowser chromiumWebBrowser,
	string selector,
	TimeSpan? timeout = null,
	bool removed = false


Type: CefSharpIWebBrowser
ChromiumWebBrowser instance (cannot be null)
Type: SystemString
querySelector for the element e.g. #idOfMyElement
timeout (Optional)
Type: SystemNullableTimeSpan
removed (Optional)
Type: SystemBoolean
(Optional) if true waits for element to be removed from the DOM. If the querySelector immediately resolves to null then the element is considered removed. If false (default) waits for the element to be added to the DOM.

Return Value

Type: TaskWaitForSelectorAsyncResponse
A Task that resolves when element specified by selector string is added to or removed from the DOM.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IWebBrowser. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
This function is typically used in conjunction with javascript that directly or indirectly adds/removes an element from the DOM. Unlike the puppeteer version navigations aren't handled internally, the method will throw a TimeoutException if a navigation occurs whilst waiting to resolve.
string script = "const newDiv = document.createElement('div'); = 'myElement'; document.body.append(newDiv);";
await Task.WhenAll(
See Also