You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The package requires CefSharp 104.4.180 or greater.
Supports keyboard, mouse and touch emulation for automating websites.
The following examples are an excerpt from the Readme
// Add using CefSharp.Dom to access CreateDevToolsContextAsync and related extension methods.awaitusingvardevToolsContext=await chromiumWebBrowser.CreateDevToolsContextAsync();// Get element by Id// https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorvarelement=await devToolsContext.QuerySelectorAsync<HtmlElement>("#myElementId");//Strongly typed element types (this is only a subset of the types mapped)varhtmlDivElement=await devToolsContext.QuerySelectorAsync<HtmlDivElement>("#myDivElementId");varhtmlSpanElement=await devToolsContext.QuerySelectorAsync<HtmlSpanElement>("#mySpanElementId");varhtmlSelectElement=await devToolsContext.QuerySelectorAsync<HtmlSelectElement>("#mySelectElementId");varhtmlInputElement=await devToolsContext.QuerySelectorAsync<HtmlInputElement>("#myInputElementId");varhtmlFormElement=await devToolsContext.QuerySelectorAsync<HtmlFormElement>("#myFormElementId");varhtmlAnchorElement=await devToolsContext.QuerySelectorAsync<HtmlAnchorElement>("#myAnchorElementId");varhtmlImageElement=await devToolsContext.QuerySelectorAsync<HtmlImageElement>("#myImageElementId");varhtmlTextAreaElement=await devToolsContext.QuerySelectorAsync<HtmlImageElement>("#myTextAreaElementId");varhtmlButtonElement=await devToolsContext.QuerySelectorAsync<HtmlButtonElement>("#myButtonElementId");varhtmlParagraphElement=await devToolsContext.QuerySelectorAsync<HtmlParagraphElement>("#myParagraphElementId");varhtmlTableElement=await devToolsContext.QuerySelectorAsync<HtmlTableElement>("#myTableElementId");// Get a custom attribute valuevarcustomAttribute=await element.GetAttributeAsync<string>("data-customAttribute");//Set innerText property for the elementawait element.SetInnerTextAsync("Welcome!");//Get innerText property for the elementvarinnerText=await element.GetInnerTextAsync();//Get all child elementsvarchildElements=await element.QuerySelectorAllAsync("div");//Change CSS style background colourawait element.EvaluateFunctionAsync("e => e.style.backgroundColor = 'yellow'");//Type text in an input fieldawait element.TypeAsync("Welcome to my Website!");//Click The elementawait element.ClickAsync();// Simple way of chaining method calls together when you don't need a handle to the HtmlElementvarhtmlButtonElementInnerText=await devToolsContext.QuerySelectorAsync<HtmlButtonElement>("#myButtonElementId").AndThen(x => x.GetInnerTextAsync());//Event Handler//Expose a function to javascript, functions persist across navigations//So only need to do this onceawait devToolsContext.ExposeFunctionAsync("jsAlertButtonClick",()=>{_= devToolsContext.EvaluateExpressionAsync("window.alert('Hello! You invoked window.alert()');");});varjsAlertButton=await devToolsContext.QuerySelectorAsync<HtmlButtonElement>("#jsAlertButton");//Write up the click event listner to call our exposed function_= jsAlertButton.AddEventListenerAsync("click","jsAlertButtonClick");//Get a collection of HtmlElementsvardivElements=await devToolsContext.QuerySelectorAllAsync<HtmlDivElement>("div");foreach(var div in divElements){// Get a reference to the CSSStyleDeclarationvarstyle=await div.GetStyleAsync();//Set the border to 1px solid redawait style.SetPropertyAsync("border","1px solid red", important:true);await div.SetAttributeAsync("data-customAttribute","123");await div.SetInnerTextAsync("Updated Div innerText");}//Using standard arrayvartableRows=await htmlTableElement.GetRowsAsync().ToArrayAsync();foreach(var row in tableRows){varcells=await row.GetCellsAsync().ToArrayAsync();foreach(var cell in cells){varnewDiv=await devToolsContext.CreateHtmlElementAsync<HtmlDivElement>("div");await newDiv.SetInnerTextAsync("New Div Added!");await cell.AppendChildAsync(newDiv);}}//Get a reference to the HtmlCollection and use async enumerable//Requires Net Core 3.1 or highervartableRowsHtmlCollection=await htmlTableElement.GetRowsAsync();awaitforeach(var row in tableRowsHtmlCollection){varcells=await row.GetCellsAsync();awaitforeach(var cell in cells){varnewDiv=await devToolsContext.CreateHtmlElementAsync<HtmlDivElement>("div");await newDiv.SetInnerTextAsync("New Div Added!");await cell.AppendChildAsync(newDiv);}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
CefSharp.Dom is an asynchronous library for accessing/modifying the DOM.
The following examples are an excerpt from the Readme
Beta Was this translation helpful? Give feedback.
All reactions