I've scoured the internet (including answers from this site) but nothing appears to work for me. Does anyone know the correct approach to attach WatiN to a WebBrowser instance (Windows Presentation Forms version)?
Most of the answers I've read tell me about 'ActiveXInstance', which is not visible in the WPF version of WebBrowser. I've tried exposing the IWebBrowser 2 interface from the WebBrowser documentation (http://msdn.microsoft.com/en-us/library/cc491073%28v=VS.90%29.aspx) but after much reworking of the code structure to get it to compile, a simple WatiN goto(URL statement simply ends up timing out.
As a last resort I've tried
WatiN.Core.Settings.AutoStartDialogWatcher = false;
var browser = new IE(wbrowser);
On the loadcompleted event (as the browser instance will result in null if I place it in the MainWindow() constructor method), but that brings up an Argument Exception with the message "iwebBrowser2 needs to implement shdocvw.IWebBrowser2". Unfortunately I've no idea how to resolve this.
It's likely that you'll want to attach by window handle:
var ie = IE.AttachToIE(Find.By("hwnd", containerHwnd);
In the WatiN_IE_ExtensionMethods.cs API I wrote for O2, I was able to get it to work quite nicely with the normal WinForms webbrowser (inside another WinForm control or an WPF control).
Since you can use WinForm controls inside WPF (and that is exactly what .NET 3.5 is doing with the WPF WebBrowser since it is not a native WPF control), here is an example that: does exactly that Using WatiN to inside WPF.
This video shows an O2 script that uses this technique: http://www.youtube.com/watch?v=YsVX5-nGHWI
Note that I wrote a bunch of Extension methods to make WatiN easier to consume:
var ie = winFormsPanel.add_IE();
ie.open("http://www.google.com");
ie.link("Videos").flash().click();
ie.field("q").value("OWASP O2 Platform").flash();
ie.button("Search Videos").flash().click();
ie.link("O2 Platform - XSS PoC builder.avi").scrollIntoView().flash().click();
Related
I've started using FlaUI for Automating my thick client .net application. The application is Windows Form based. The start was good and Login Form was identified and I could Login, but after that came the dead end and I found that almost everything in the application is developed as Pane control type.
So, there is grid, table etc. but they all just appear as Pane type when I see the object hierarchy using Inspect.exe or FLAUInspect tools. And nothing really appears in thier property, so it seems that nothing could be read. But before giving up I just wanted to check with experienced audience on this forum if there is really any way to get the data from Pane objects.
Please suggest if there is any way, even that means using other libraries like UIAutomation, TestStack.White, etc.
UPDATE: I now understand little more about this. So, the objects that are there in the pane are developed in syncfusion and devexpress. Is it possible to identify objects developed in syncfusion and devexpress using FlaUI or UIAutomation or TestStack.White, etc ?
I don't know if you have already tried the following steps. Have you add automationId's to your objects in xaml code with:
AutomationProperties.AutomationId="AnyID"
In the testcode, first initialize the main window of the application.
MainWindow = fApplication.GetMainWindow(fAutomation, null)?.AsWindow()
After that you can find your objects by the automationId's, like:
MainWindow .FindFirstDescendant(cf => cf.ByAutomationId(AnyID))
I did it this way, and don't have to know the hierarchy of my application. Maybe this will work?
Most UI Frameworks nowadays fully support UI Automation. So first make sure that you have a recent version of your framework (syncfusion, devexpress). In addition, some frameworks provide settings to enable UI Automation. Like for devexpress, you need to set
ClearAutomationEventsHelper.IsEnabled = false;
at the start of your application to test so it exposes way more things (like tabs) to FlaUI.
I am using mshtml.InternetExplorer object within my winforms application to browse a web application. Somehow I can't use webbrowser in my solution. Now I need to capture screenshot of a div element inside this web application. I see lots of solutions doing similar functionality using webbrowser's drawtobitmap method but none is using mshtml.InternetExplorer.
Is there way to achieve this functionality ? Is there some way that I can type cast InternetExplorer object into webbrowser?
You should be able to capture the desired part of the main IE window using PrintWindow Windows API, as explained here. You can get the handle of the window by calling IWebBrowser2::HWND on the IE object. Some other methods could also help to make this happen:
IWebBrowser2::ClientToWindow
IHTMLElement::scrollIntoView
IHTMLElement2::getBoundingClientRect
I'm trying to click a button on a windows application from other application. Basically, I want to click app B's button from app A's code.
I can use winapi findWindow to get a handler. The problem is that I have no idea the name of the button on the app B. Is this possible to list all the names or ids of an application?
I'm using c# to make it happen.
Since you're looking at suggestions (it's a pretty generic question really, it might or might not work depending on what other app/window is, is it e.g. browser or a 3rd party app etc., does it support automation)
Take a look at this closely related answer (it might be a duplicate but you're kind of 'looking for' still so maybe note).
Accessing Elements from Other Processes
Also this one on how to 'access' other app's 'inputs'
Pinvoke SetFocus to a particular control
I have not tested this. But it looks like a intressting libary. Maybe there is some function you can use. It is called White. This is just a sample:
Application application = Application.Launch("foo.exe");
Window window = application.GetWindow("bar", InitializeOption.NoCache);
Button button = window.Get<Button>("save");
button.Click();
You can use tool such as Spy++ (included in any Visual Studio except Express editions) to find name and class of that button and then use these information as parameters of FindWindow().
I'm trying to load a HTML page via the web browser control in my Silverlight project, but it seems that the content of the control can only be viewed from out-of-browser mode.
Is there in way to use it in the browser?
Could you give more detail? if you are wanting to control and interact with the WebBrowser Control in the Internet Explorer window, then you can do this. The code will remain the same, except you will need to change your MSHTML DOM reference when declaring your (say) HTML Document, and it'll be declared as an InternetExplorer type (comes up in intellisense after the "As" part if you're using VB, same story with c#).
Once you reference this window, you can control it - everything is the same since IE uses the WB control as well, if you however want to use the WB control in your app, you should be able to, give us some more details, are you saying that the content or links are opening up in a new external IE window? If that is the case, these things are fixable :).
Also, if you're using WPF .NET I think there is a different, less cooler WB control for that than the traditional .NET WB control. Please elaborate on your question so I can help you further.
How to use C# to capture a image of a specific url?
I want to use C# to automatically capture a image of a webpage based on a specific url.
For example, I have a page contains a txtUrl.Text = "http://www.some.com/index.aspx" , then I click a button, how can I capture a image of that Url?
I assume you want to do this from ASP.NET (as opposed to from a WinForms application).
In your web project, add a reference to System.Windows.Forms (yes, this is a bad thing to do). In your code-behind, you can then create an object of type System.Windows.Forms.WebBrowser:
WebBrowser browser = new WebBrowser();
// this will load up a URL into the web browser:
browser.Navigate(#"http://www.stackoverflow.com");
Next, just use the BitBlt API function (sorry, I don't have a link handy) to copy the WebBrowser control's graphical display to a Bitmap (which you can then display or save or whatever). With this function, the WebBrowser's Handle property is one of the parameters to pass.
Update: here's a link to some code that does exactly what you need: http://www.developerfusion.com/code/4712/generate-an-image-of-a-web-page/
If you mean a visual of the webpage, one approach is to integrate IE to your application and programmatically taking a screenshot. This (for the integrated web browser) and this (for taking screenshots with C#) may be of use. This is of course IE dependent.
Another option is using the shotserver and shotfactory projects used for browsershots.org. They can be found here, though I'm not sure if there's a .NET API for it.
I don't think that is really possible only using C#. That is because C#, or the .NET framework for that matter, don't offer any kind of HTML markup rendering capabilities. The closest you can get - in my opinion - would be to use a WebBrowser control and then try to somehow capture it's graphical output (which would be the rendered page).
The other way to do it would be to look for a .NET component that might do what you want.. Although I don't know of any that do.