Self-contained browser automation for C# without external dependencies

I need to create automated scripts that can interact with web pages, run JavaScript code, locate elements using XPath selectors, and simulate user interactions like clicks and text input. The main challenge is that my application needs to be completely standalone.

I’ve tested Selenium which works great for automation tasks, but it requires users to have Chrome or Firefox already installed on their system. This creates deployment issues since I want to distribute a single executable.

I also tried CefSharp which bundles Chromium directly into the app, but it lacks advanced features like XPath support and doesn’t have the same automation capabilities as Selenium.

What I’m looking for: A C# library or framework that provides full browser automation features (JavaScript execution, element selection, user event simulation) while being completely self-contained without requiring any pre-installed browsers on the target machine.

Playwright’s another solid option. It comes with its own Chromium build and has built-in xpath support - unlike the others. The C# API is clean and handles all that automation stuff you need. Deployment’s a breeze since everything’s packaged together - no separate downloads or runtime installs. I’ve been using it for 6 months and it’s been rock solid.

Check out Microsoft.WebView2 with the fixed version runtime. You can bundle it with your app deployment, so no external browser needed. Takes more setup than Selenium, but WebView2 handles JavaScript and DOM stuff through its CoreWebView2 API. One catch - no native XPath support. You’ll have to run JavaScript with document.evaluate() for XPath queries. I’ve used this in production when we couldn’t count on users having specific browsers. Runtime adds ~100MB to your package, but you get solid automation across Windows versions without needing admin rights to install.

I’d go with PuppeteerSharp. It automatically downloads and manages Chromium, so you don’t need to install anything. The API’s solid for automation - handles JavaScript execution and element manipulation well. XPath isn’t built-in, but you can run XPath queries through evaluate functions just like regular Puppeteer. I switched after CefSharp kept hitting walls. Only downside is the 170MB Chromium download on first run, though you can bundle it at build time. Performance beats WebView2 in my experience, especially for headless automation.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.