In BluePrism it is possible to spy buttons, fields etc. of any windows application and then click those buttons automatically. For example, if you look at the screenshot you can see the attributes of the calculator's button "1" as spied in the Win32-mode (there are also HTML-, Accessibility-, Region- and UI Automation-modes) by which BluePrism will be able to identify and click the according button. Furthermore, BluePrim is compatible with C# and I wonder whether (and how) I could also get those attributes via C# instead or at least use the spied attributes as can be seen on the screenshot to press the same button with C# instead?
EDIT:
It would be highly appreciated if someone could provide the C# code for pressing the calculator's button "1" to get me started (I'm a C# newbie :-) Thanks!
You do not need C# for that, you can just use a Reader stage and action Get AA Attribute or Get Window Attribute.
EDIT:
But if you really want to do it using .NET only, have a look at UI Automation or Active Accessibility Automation (older one)
This seems like a nice example.
You will also find a tool called Inspect.exe very handy to spy elements without using BP. This
You can use the Application Model that you just spied, put it in a navigate stage in your object, then select Click Mouse Centre as the action. This will result in the button you have spied being clicked. Generally, to use Sendkeys is with C# syntax, i.e. use the root element (root element and top of list in Application Modeller tree) and select Global SendKeys as the action inside a navigate stage. In the Text input field you can enter your C# sendkey code, like for example for Ctrl + Alt + Delete use: "^%{DELETE}". I think this is what you may be looking for? Otherwise, if I understand correctly, you might be looking to use a C# code-stage inside BP to pass sendkeys to an application attached to a BP process, which would possibly involve referencing each and every attribute of the host application in C# and then using (for example) the C# Enum properties of each keyboard key, etc... this would be a massively redundant exercise since BP already provides the functionality inside the navigate stage as explained above.
Related
I have a very strange request that might upset some of you, anyway I want to write text or numbers in the website using C# or wpf software.
What I want is I pass string or number to the website when I press for example F11 on the keyboard and that number or string can be from a textbox.
Assume the following is Grid on a website:
Now I want to pass 0.01233 from textbox, to the highlighted cell in the website using c#.
Can anyone please how this can be achieved or at least guide me which direction I should go and achieve this.
Please Note I am not a developer of website and I have no control on website, I cannot write script on website
I've done something like this before, though I can't seem to find my old code. WPF has a WebBrowser control. You can use the Document property to access elements of the webpage an (if I recall correctly) execute scripts assosiated with those elements.
Of course it goes without saying that this would be a bodge at best, since any change made to the website could break your code.
Also, this forces you to use the WPF WebBrowser instead of your browser of choice.
I am currently working on a Windows Presentation Foundation app and I need to make use of Message boxes. I want to get few information from user inside Message Box popup.
But they appear always like this:
But I think the actual look of it should be like that:
Does anybody know, why this is, and how to solve it? I tried all everything listed
here
, but nothing worked.
I agree with Keithernet, build your own. Its more of an Input Dialog box. You may want to plan it to create a window, create it with ex: 4 parameters which you could override so you can apply them in the form including
The title,
The prompt you want the user to fill in
optional default button 1 text
optional default button 2 text.
have the input value stored into a public property in the window for the text to be bound to during entry.
If the user clicks the cancel button (or similar), clear the text entry and close the window. If ok button, just close the window.
Then, when you call it with a YourWindow.ShowDialog(), upon return, you can look at the public property for that input text value.
You could even do with a property / flag if the user cancelled directly or not. I have done similar in a couple of my WPF apps.
MessageBox is very limited. Based on your screenshot, you should just create your own child Window with your own XAML so you can get the user input.
You can find sample service implementations/NuGets for this on GitHub. Here is one I've created sometime ago: https://github.com/Dirkster99/MsgBox
Just create your own is an oversimplifying statement in my opinion because this is usually a dialog that you want to show in different parts of the application. Therefore, you have to settle for a software design pattern (I chose a service implementation as suggested here).
Likewise, there are other design decisions that should be taken. I have for instance made sure that the API has a compatible subset of Show API calls with the standard .Net MessageBox to make its application as flexible as possible. I also settled for light and dark themes hoping this will make its application easy in any other theme...
I'm trying to make an application that will test some features of an existing app and I wanted it not to be window-size dependent and not to require focusing the window or etc.
I've already figured out how to get window handles for different controls in the tested app so I can click buttons, enter text to textboxes etc. with Send/Post Message but still got a few unsolved problems.
The first is selecting an item from a pop-up menu that can be triggered by button click (TAdvGlowMenuButton class) or right click somewhere- I can't even see any messages related to it in Spy++ so I have no idea how to do it, is it possible to select an item by name? as I don't have it's id
The second thing is clicking next to something, for example 10 pixels to the right of a button.
I have the button handle so I can get it's size and it's parent but I still don't know how to get it's position inside the parent - any ideas?:)
And also a quick one but I don't believe it is possible - can I somehow get position of a label in the tested app? I can't even see it in Spy++ .
I hope you can help me to find it out ;)
Edit: I forgot about the most important thing:P , I'd like to achieve it with Send/Post Message if only it is possible.
My recommendation would be to abandon the message sending/posting model altogether and instead use UI Automation. Automated testing tools is exactly what the UI Automation APIs were designed for, and they are much more capable than SendMessage/PostMessage.
Yes, I realize that this is exactly the opposite of the answer you were looking for. But you will have no end of trouble getting messages to do what you want. A fair number of them rely on the application having the focus, and it is completely reasonable for your code to make this assumption when you receive e.g. a WM_KEYDOWN message. A testing tool should not flag that as a bug.
I notice you've tagged this question with the C# and .NET tags. In that case, you may be interested to learn that the UI Automation APIs have been wrapped in the .NET Framework.
I'd like to be able to do following actions within another application:
to change Tabs
to Copy text from within a TextBox
to click on a Button
to enter text into a TextBox
to select DropDownList element
Right now I'm using separate methods such as:
mouse_event() to change mouse coordinates and click on a button
another mouse_event(LeftMouseClick followed by the RightMouseClick) to copy a text within a TextBox
Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text) to Copy what's inside the clipboard
SendInput (for each key) - enter the text into a TextBox
Disadvantages of this approach are:
(not crucial) PC becomes unusable (you can't work while script is running)
I have to know exact pixels (read - position/coordinates) of EVERY element within an app
slow execution time (each key has to be typed separately)
I'm looking forward to create an application which can click on a TextBox/Button/List without the need of having exact coordinates of these elements.
Is such task possible with C# WinForms? My current approach works but it has it's flaws.
Any advice?
Read about Mutex. If you plan on scale-ability, read about network communication (for example, the TCP protocol. TcpListner, and TcpClient).
This sounds like a job for UI Automation. I have only used it to get text from another application, but it has functions to activate controls by name or to navigate the control tree if there is no name.
You can get text and interact with controls using AutomationElements that you find using patterns or navigating the control tree.
There is a complete framework for doing exactly this kind of thing, and it's called the UI Automation Framework
Here's some examples on how to use it.
And you can also apply this technique to generic windows's using the UI Spy to determine the automation elements.
I've been searching for days about this, but haven't found anything.
I am trying to find out how I can add a context menu item to the windows explorer. I do not want it for specific filetypes, BUT I want it to appear on everything inside a specific path.
For example, I want right-click menus of anything inside "C:\folder" to contain this item, but it shouldn't appear outside this folder...
Is that possible?
Any help will be really appreciated!
Thanks in advance,
John.
The normal way this is achieved is to add it to the Registry under:
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
However in your specific case you want to do some preprocessing before it is displayed (eg is it in the specified directory) which wouldn't work with a simple registry alteration.
I think there is a way to force you way into any operation and add a hook to it. I'm talking about old school knowledge now though and I cannot think what the technology would be called. I think its how you would have, for example, forced your way into the rendering engine to put custom skins on normal explorer windows or inject an extra button into the title bar of apps like you used to see back in the day.
It just occurred to me that adding a button to the windows title bar might have given a search starting point, I found this article which refers to subclassing windows components and injecting your own behaviour. I think that is what I'm talking about above:
http://www.codeproject.com/KB/wtl/titlebar.aspx
Hope this gives you a new direction to search in.