-
-
Save natritmeyer/966981 to your computer and use it in GitHub Desktop.
/* | |
Create a console app, add references to the various white libraries and use the following as a template for operating the Open Dialog window | |
Get the white binaries from here: http://white.codeplex.com/ | |
*/ | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Windows.Automation; | |
using White.Core; | |
using White.Core.UIItems; | |
using White.Core.UIItems.Finders; | |
using White.Core.UIItems.WindowItems; | |
namespace OpenFile | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Application myApp = Application.Attach("YOUR_APP_PROCESS_NAME_HERE"); | |
List<Window> myWindows = myApp.GetWindows(); | |
Window openDialog = myWindows.Where(n => n.Name == "Open").First(); | |
TextBox textField = openDialog.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit).AndByText("File name:")); | |
textField.Text = args.First(); | |
Button openButton = openDialog.Get<Button>(SearchCriteria.ByControlType(ControlType.Button).AndByText("Open")); | |
openButton.Click(); | |
} | |
} | |
} |
Hi Guys,
I have a requirement i need to automate a web application using c#.
Right now i have created a windows form application and have used web browser tool in tht.
But im struck on open dialog file i can able to select the file but i cant able to clcik the open button.Can u explain how to do in web browser.
This code works perfect on Windows 10. It doesn't work on Windows 7.
On Windows 7 the Open button looks like this:
On Windows 10 th Open button looks like this:
I guess that extra arrow makes it impossible for TestStack.White to find the button with this code:
Button openButton = openDialog.Get<Button>(SearchCriteria.ByControlType(ControlType.Button).AndByText("Open"));
The exception I got:
TestStack.White.AutomationException: Failed to get (ControlType=button or ControlType=check box),Name=Open,ControlType=button
Any idea on it? Pressing enter may be a good solution, but I prefer to tell explicitly which button to press.
childWindow.Get(SearchCriteria.ByAutomationId("1148")).Select(1);
var OpenButton = childWindow.Get(SearchCriteria.ByClassName("Button").AndAutomationId("1"));
OpenButton.DoubleClick();
works for me.
Worked great for me. Thanks @natritmeyer