.NET Development
Lost inside WebBrowser control
Gravatar is a globally recognized avatar based on your email address. Lost inside WebBrowser control
  Sep 5, 2017 @ 08:26am

Hi Rick Strahl, I would like some help.
I would like to automate ? having my web server sign-on to a remote site, press some selection keys and enter some selection criteria values, see the list that was selected, and then press their download button, determine when their download has completed, read the downloaded CSV to insert into my table, erase the CSV, logoff the remote site, and give my user the record count of what was loaded. phew and probably do this 3 or 4 times for different criteria and CSV files. (outlined visually on the next page)

I am working in (laptop quick and dirty prototype, vs final desktop more current) C# (VS2008, and VS2013),
.Net v2.0 and v4.0, IIS 7 and WinServer 2012 Win 7 and Win 10, SqlServer 2008R2 and 2015 I have looked at WebBrowser via STA in web app (current frustration) WebClient (briefly) iFrame read a little about JSONP (works only for Get, not PUT ??) read some on Cross Domain?? I do not control the remote target server.

I’m currently stuck in WebBrowser trying to click on Login button. The button’s js checks for presence of user/pswd, and when I omit one it returns errormsg that I can GetElementById. So I know that I am getting that far in the js.
The js then has $.AJAX({ with JSON to send user/pswd back for auth, but I can’t tell if anything is going across the network. And some blogs suggest that AJAX silently balks at CrossDomain.

Your very own “JavaScript Debugging in a Web Browser Control with Visual Studio” did not seem to work for me… my WebBrowser instance is dynamically created via C# in the IIS web server… and runs their js

Fiddler seems only to intercept Chrome browser /or/ IE browser going to Target. (and chokes on Firefox)… Fiddler does not seem to display any IIS traffic to/fro the network.

Should I continue with WebBrowser control or switch to something else? If I do manage to Login with valid user/pswd, what does WebBrowser do to close the prior screen and receive the response? Does it give a new DocumentCompleted event? Should I add HttpHandler and inject CORS Access-Control-Allow-Origin: * Or perhaps wait until I get a real X-domain error message? How can I see network traffic to/fro IIS? What folder is used for their CSV download when IIS clicks on Go? (any other comments on approach?)

Tkx, Paul Gerken

Gravatar is a globally recognized avatar based on your email address. re: Lost inside WebBrowser control
  Rick Strahl
  Sep 5, 2017 @ 02:57pm

Crossdomain is a real issue, however if the Web page interactively can do it, so can an automated page using the same Web Browser control as long as you are navigating from the same domain.

Complex user interface automation via browser is difficult, but there are specific test tools like Selenium and others that have Domain Languages that make it easier to automate browser UI (mainly for testing purposes). I would look into that before doing something manually.

That said it probably is possible to do what you need with just the Web Browser control - it's just tedious and time consuming.

No matter how you go at this though, this sort of automation tends to be very fragile - any change can break the whole thing and most likely the UI wasn't designed (or actively designed not to) to be automated. So I'd be very wary on spending a bunch of time trying to automate a browser based UI unless you control the other end.

+++ Rick ---

© 1996-2018