1

I need look-less web-browser to interact with some web-page (e.g. enter text, click some button, then read some DIV element). How can I accomplish it in WPF? I tried using System.Windows.Controls.WebBrowser, but apparently it must be rendered to interact with:

var b = new WebBrowser();

b.LoadCompleted += (sender, args) =>
{
    // I never get here...
    Trace.WriteLine(args.Content != null ? "Success" : "Failure");
};

b.Navigate("https://www.google.com");

How can I use it in a non-visual way? or is there a better alternative?

Tar
  • 8,529
  • 9
  • 56
  • 127

2 Answers2

1

The WPF WebBrowser flavor needs a parent window with live Win32 window handle. Instead, you can use the WinForms WebBrowser version, which can exist without a parent window. Just reference System.Windows.Forms.dll assembly in the project. Internally, either version wraps the WebBrowser ActiveX Control.

I posted a few examples of how to do this. Note most of them are console apps, so they create a secondary STA thread to run a message loop for WebBrowser. In WPF, you can use WinForms WebBrowser on the main UI thread.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486
0

if you don't need any java script to be executed you could use WebRequest
(there is an example at the bottom of the MSDN page...)

user1859022
  • 2,585
  • 1
  • 21
  • 33
  • But then I have to start playing with `POST`s, `GET`s and so on... I find it simpler to just send input text to `DOM` elements. Besides, I have to start analyzing the web site to see how to interact with it, when I can just simulate it... – Tar Jul 10 '14 at 11:46
  • so if you really want to stick with the `WebBrowser` control couldn't you just crate a window containing the control and hide it? – user1859022 Jul 10 '14 at 11:49