WebBrowser - Modal('Show') and Javascript - c#

I'm using a standard WebBrowser control to perform various automated web requests. I am aware of the default IE 7 setting unless changed by registry, which I have done, and now use a mainly functional version of IE 10 embedded within my program.
Unfortunately, there are times when I need to click JS buttons to add data to the displayed webpage, and other times when there are Modal popups that require me to input information. Webbrowser chokes on this, and for the button, and popup, does nothing.
I am aware of the route of using ScriptInvoke to send my data, but I wondered if there is any way I can avoid this and just use the WebBrowser control as if it where a normal browser, that accepts the two described functions.
Thanks to all,
Stan.

Related

Monitor and simulate javascript activity in .NET Webbrowser Control?

Traditionally, if one wanted to monitor clicks in IE, you could do it by creating a Browser Helper Object. However, with modern javascript heavy websites (angularjs etc), the traditional click monitoring doesn't work.
Is it possible to monitor javascript clicks in the .NET Webbrowser Control? What if I wanted to simulate a javascript click? Use case is that I have the same site opened on two different .NET Webbrowser controls on two different PCs (both created by me). Lets assume the site is based on angularjs (or some other javascript framework), when the user clicks a link, dropdown etc, on machine A, I want to be able to send a command so that the same action is performed on machine B.

How can I open a webpage first and then fill in text boxes and click a button and visibly view the results?

[edit] It is a requirement that the webpage spawn and open in IE and allow user manual interaction after the programmatic actions have completed.[/edit]
I've seen a lot of code examples online about opening webpages or filling in webpage textboxes and getting a return value without ever opening them visibly.
I would like to open a webpage in IE, fill in a few textbox buttons
and then click the submit button and view the results visibly.
I am able to do this with a dll called Selenium, but I do not want to use a 3rd party application and it seems that WebBrowser() should be able to do this?
I can post my failed code examples if that would help.
Thanks.
Maybe this qould fit better as a comment, but I don't have enoigh reputation.
Do you know how HTTP-Forms work?
It would probably be easier to send a HTTP-Request to the target of the form you want to fill, including the parameters you would like to fill into the form.
So you don't need any WebBrowser or similar, just a simple HttpWebRequest object, where you specity the target, the method (very likely POST) and the data you'd like to send.
You can use the webbrowser control in Winforms. It is possible to access every DOM object of the website using the control. No need to open the IE externally.
You just need to specify the webbrowser URL as your link.
Then, fill the textboxes with code,
BrowserID.Document.GetElementById("TextboxID").SetAttribute("Value", "NewVaue")
Also, you can click on the button using InvokeMember("click").
There are lots of stuff using WebBrowser. You can learn it here.

how can i use IE (or different browser) for each webbrowser controle?

i want to use different browsers for my webbrowser controls in c#.NET.
for example, if im log into facebook from the webbrowser1, i will not in the webbrowser2
if i cant use ie different for each webbrowser... can i separate cookies for each webbrowser control?
for example, if i navigate using the first controle
webbrowser1.navigate("this is not important");
then submit the login form
webbrowser1.document.getelem..... click
thats will not applicated on the secod control( webbrowser2)
-
i hope you inderstand what i want :)
The WebBrowser control is a wrapper around IE and will always and only use IE. It's never going to use Firefox or Chrome etc. Some browsers apart from IE may allow Automation, but you'll have to check their documentation.
In your two lines of code, both are using the control called webbrowser1, so the Navigate and getelement will always go to the control. If you want to use two browser instances, you need to have 2 controls.
I don't clearly understand what your question is. The two points above are what I can answer.

Windows Phone browser live html modification

I haven't looked into it very much but am struggling to find relevant information on the topic. I basically want to create a browser that applies a filter to a webpage by changing colors in a webpage. My guess is that I will have to change the html once loaded or something, would this work? Do I have other options?
PS. I don't just want to make every color darker, I would more like to invert the colors.
Edit:
If any you were wondering, I am talking about the XAML browser component that can be used in a Windows Phone application.
I think the simplest way to do that is to inject some Javascript into your page once it has loaded.
To do that, you need to set the IsScriptEnabled to true on your WebBrowser control and then subscribe to the Navigated event.
When that event occurs you can inject some JS codeby using the WebBrowser.InvokeScript method.
Here is an example of JS code that darken the page : JavaScript: Invert color on all elements of a page
If you are talking about in a PC internet browser, you can find an add-on to execute Javascript automatically, such as Greasemonkey for Firefox. If you are talking about Windows Phone's Internet Explorer, I don't really know what you could do there, as I don't think they allow add-ons.

Interacting with web pages in C#

There is a website that was created using ColdFusion (not sure if this matters or not). I need to interact with this web site. The main things I need to do are navigate to different pages and click buttons.
I have come up with two ideas on how to do this. The first is to use the WebBrowser control. With this, I could certainly navigate pages, and click buttons (According to This).
The other way is to interact with the html directly. Not sure exactly how to do this, but I am assuming I could click buttons or use HTML requests to interact with the page.
Does anyone have a recommendation on which way is better? Is there a better way that I haven't thought of?
I'd use Html AgilityPack to parse the html and then do POSTs and GETs appropriately with HttpWebRequest.
While it may be possible to use the WebBrowser control to simulate clicks and navigation you get more control with Html AgilityPack and HttpWebRequest regarding what gets sent
Did you consider Selenium? The WebDriver API is quite good, and permits a lot of things in terms of Website automation.
why not submit directly the url? that's what the button click will do.
using WebRequest.Create you can submit directly to the url. no need to load, parse and "click" the button.
HtmlAguilityPack is useful for pulling the web elements and finding tags easily. If you need to remotely "steer" a web session, though, I prefer to use WatiN. It bills itself as a web unit testing framework, but it's very useful anytime you need to fake a browser section. Further, it can remote control different browsers well enough for most tasks you'll need (like finding a button and pushing it, or a text field and filling in text if you need a login).

Categories

Resources