WinForms Web Browser control forcing refocus? - c#

I'm trying to automate a web process where I need to click a button repeatedly. When my code "clicks" that button (an HtmlElement obtained from the WebBrowser control I have on my form) then it brings focus back to my application, more specifically the WebBrowser control. I wish to better automate this process so that the user can do other things while the process is going on, but that can't happen if the window is unminimizing itself because it's attaining focus.
The code associated with the clicking is:
HtmlElement button = Recruiter.Document.GetElementById("recruit_link");
button.InvokeMember("click");
I've also tried button.RaiseEvent("onclick") and am getting the exact same results, with focus problems and all.
I've also tried hiding the form, but when the InvokeMember/RaiseEvent method is called, whatever I was working on loses focus but since the form is not visible then the focus seems to go nowhere.
The only non-default thing about the webbrowser is it's URI being set to my page and ScriptErrorsSuppressed being set to True.

Why do You need to click this button? It's sending some form?
If yes, you can use WebClient and simulate sending form without graphic interface.
Basicly almost anything significant requires connection to website using Get Post or multipart/post so WebClient will be perfect. You can simply get the site wich is this button on and parse it to get what clicking it do. And then simulate your own action.

In IE7 or higher you can implement IProtectFocus on the webbrowser site and deny the focus change. You would be much better off if you use the raw ActiveX or its wrappers that support this kind of customization, e.g. csexwb. If you have to use the winform webbrowser control, you need to create your own webbrowser site.

Related

Visual Studio 2015 How to make the WebBrowser control unclickable

So I'm trying to make a simple app for me and my friend. The app is used for his radio station. I currently have a basic WebBrowser control. The WebBrowser control is locked at a certain location on twitter, so that you can see all the tweets his radio station tweets out.
It looks good and works fine. The last thing I need to do is to make the WebBrowser control unclickable, whilst you can still scroll through the internet page. This means that I don't want people to be able to press on a tweet in the list. I tried putting a transparent panel of the browser, this just creates a hole in the browser and shows the background.
Does anyone have an idea how to make the WebBrowser control unclickable?
A possible solution would be to stop the browser from navigating anywhere:
wb.Navigating += (s, e) => e.Cancel = true;
But I honestly don't know if that will also work for any fancy AJAX techniques.
If you want to enable some navigation you can also check for the e.Uri or possibly allow the navigation if e.NavigationMode == NavigationMode.Refresh.
I am not sure if that would work but try creating click event and place only 'return;' instruction in the event code. that should cancel the click.

making WPF webbrowser not accessible for user

maybe it's quite easy question, but I haven't managed to find a solution. I'm using web browser only to display data, and don't want user to access shown webpage. I know that in win forms' webbrowser it's possible, but how can I achieve it using WPF control?
PS I don't want to lock browser action in the navigate event, as described here: How can I make a WPF WebBrowser read-only? , because this won't stop my user from running javascripts etc
PPS And I also don't want to disable js, because I want it to be used by webpages. What is more, I'm executing it from code, as long as navigating between sites
Add this to Windows_Loaded Event
webbrowser1.IsEnabled = false;

Webbrowser and IE acts differently?

I'm in a trouble trying to fix some problem.. I have a program with Webbrowser control inside it.
It automates crawling process from some website. The problem is that I cannot fix webbrowser after recent website changes.
They have changed page navigation on website. And when I do actions MANUALLY in webbrowser (in my app) it doesn't go to the next/previous page on website. It does nothing... Whereas it works properly in IE 7/8/9 (only scripting errors thrown this time).
So does it mean that Webbrowser is not fully similar to IE??
I'm sorry for not showing source codes here, I think it wouldn't help here. Which way should I go to troubleshoot it? Why page navigation is not working in Webbrowser control?
I tried to simply put Webbrowser on a Window Form in new project and tried to navigate page 2/3/../10 in the website catalog, but it simply changes page number and doesn't navigate to it...
EDIT: Website doesn't work propely even if I do actions manually in webbrowser using mouse clicks.. but works in IE.
EDIT2: I might be not clear in my question. The problem is that I cannot use website even Manually with mouseclicks via my Webbrowser control in app. It changes page number after I click on it, but it doesn't navigate to that page. It stays silent. I'm sure that AllowNavigation property is true. It worked just yesterday and stopped after website changes today... Please tell me which way should I go to troubleshoot it.. I thought that Webbrowser control acts the same way as Internet Explorer.. Any help from you highly appreciated! Thanks
EDIT3: Strange thing... i just loaded Extended Webbrowser and navigated to that website. Page navigation panel doesn't work there also.. Is it a bug on their side or some type of guard from crawlers? What do you think?
(http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx)
I'm sure this isn't the answer your want but using the webbrowser control to scrape websites is very painful to maintain.
Instead use the HttpWebRequest and HttpWebRepsonse objects to recreate the calls to the webserver.
You can use Fiddler (http://www.fiddler2.com/fiddler2) and your browser to record your web sessions and recreate them in code.
You can setup your webbrowser control to disable a number of features including navigation.
I.e. to disable nav in the C# WebBrowser control:
webBrowser1.AllowNavigation = false;
I'd double check that you're not doing anything like this.
I had the same issue with a certain web site that recently changed its format. It has to do with the version of IE used by the control.
Simply force the IE version used to the latest (in my case 9). Setting the appropriate registry item to 9999 for my application worked; see: Webbrowser control behaving different than IE

How to complete some task on click of a button and then navigate to a different page?

I am developing a winform app which is controlling a website. On click of a button in winform app i want to fill a form, click the submit button on the web page upon which a new page will open , on that page i have to click on a link.
How to achieve this. i have tried many things but did not got any proper solution
If you're looking for a web automation tool, use Watin. It allows you to automate via code the opening of a browser, the clicking of buttons, and the fillout of form fields. However, that is more of a testing library.
Honestly though, your choice of solution sounds odd. You're trying to get a client application to make requests through a web page, instead of directly requesting whatever resource yourself from the client application. It's hard to give you a direct solution without a good understanding of the problem space.

Silverlight Browser back button to work

In my Silverlight app how can I determine if the Back button is pressed and to not logout, as it is currently doing. I may have a problem as the app is primarily a grid with drill down but at least if it could return to the start page, would be great.
I think the only way to trap that is with javascript. And the only thing you can do that way is to get an OK Cancel standard messagebox.
Or what you can do if you want to manage different pages with silvelight; create a Silverlight Navigation application (with the appropritate template).

Categories