DotNetBrowser API provides functionality that on the currently loaded web page allows you to:

  • find specified text
  • highlight all matches
  • select the first match

To find specified text on the loaded web page use the Browser.FindText() method. This method returns the SearchResult instance that provides access to search results such as the number of matches and index of the selected match.

Note: Browser performs search only through visible content on the loaded document. If some text presented on the web page isn't visible due to CSS rules, Browser will not go through this content during search. Also, Browser doesn't search text on the document with size 0x0, so make sure that Browser component is visible and its size isn't empty.

To clear search result highlights on the web page and cancel search use the Browser.StopFindingText(StopFindAction action) method.

using DotNetBrowser;
using DotNetBrowser.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FindTextSample
    class Program
        static void Main(string[] args)
            using (Browser browser = BrowserFactory.Create())
                ManualResetEvent waitEvent = new ManualResetEvent(false);
                browser.FinishLoadingFrameEvent += delegate (object sender, FinishLoadingEventArgs e)
                    // Wait until main document of the web page is loaded completely.
                    if (e.IsMainFrame)
                        SearchParams request = new SearchParams("find me");
                        // Find text from the beginning of the loaded web page.
                        SearchResult result = browser.FindText(request);
                        Console.Out.WriteLine(result.CurrentMatch + "/" + result.NumberOfMatches);
                        // Find the same text again from the currently selected match.
                        result = browser.FindText(request);
                        Console.Out.WriteLine(result.CurrentMatch + "/" + result.NumberOfMatches);

                browser.SetSize(700, 500);
                browser.LoadHTML("<html><body><p>Find me</p><p>Find me</p></body></html>");