Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all 585 articles
Browse latest View live

Automation Event Handlers are fired more than once

$
0
0

Hello,

I'm working with the MS UIA framework and its built-in Automation event handling.  I'm seeing unexpected behavior on the WindowClosedEvent.

[TestMethod] public void TestMethod1() { Process.Start(@"TestApp.exe"); Thread.Sleep(2000); //sleep to wait for proc to boot with ui

var windowElement = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "TestApp"), new PropertyCondition(AutomationElement.AutomationIdProperty, "TestAppAutomationId"))); Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, windowElement, TreeScope.Element, OnClose); var windowPattern = (WindowPattern)windowElement.GetCurrentPattern(WindowPattern.Pattern); windowPattern.Close(); Thread.Sleep(2000); //sleep to wait for uia's event threads to fire and finish. } public void OnClose(object sender, AutomationEventArgs e) { Console.WriteLine("test"); //this is run twice during the test }


Perhaps I'm doing something wrong here, but my understanding was that the Console call should be executed once.  When I run the above code the Console line is executed twice.

When my TestApp is close there are no special events that it runs.  The test app is also only a single WPF window.

I'm running against .NET 4.5.2 on Windows 10.

If I'm doing something wrong here that would cause the handler to fire more than once please let me know.

Thanks.


Need to click the hyperlink which in located in Datagrid cell using UI automation

$
0
0

Hi all,

Am working on UI automation. I can able to get the datagrid control in UI automation but I couldn't able to get the hyperlink control which is presented in all the rows in 2nd column. Kindly help me on this.

My code:

if (automationelementTSDwindow == null)
            {
                Condition condition = new PropertyCondition(AutomationElement.AutomationIdProperty, "TesterSummaryDisplayWindow");
                automationelementTSDwindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, condition);
            }

            GridPattern gridControl;
            int integerElementPosition = -1;
            long rows;
            long columns;
            string[,] returnArray = null;
            ValuePattern dataItemControl;
            bool returnValue = false;
            bool direction = false;
            if (findAllElementsOfAType(ref automationelementarrayGridCollection, ControlType.DataGrid, automationelementTSDwindow))
            {
                integerElementPosition = getPositionInArrayBasedOnAutomationID(automationelementarrayGridCollection, automationID);
                gridControl = automationelementarrayGridCollection[integerElementPosition].GetCurrentPattern(GridPattern.Pattern) as GridPattern;
                rows = gridControl.Current.RowCount;
                columns = gridControl.Current.ColumnCount;
                string[,] dataArray = new string[rows, columns];
                string temp;
                scrollVerticalReset();
                scrollHorizontalReset();
                do
                {
                    direction = !direction;
                    do
                    {
                        //System.Threading.Thread.Sleep(100);
                        for (int i = 0; i < rows; i++)
                        {
                            for (int j = 0; j < columns; j++)
                            {
                                try
                                {
                                    if (dataArray[i, j] == null)
                                    {
                                        dataItemControl = gridControl.GetItem(i, j).GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                                        temp = dataItemControl.Current.Value;
                                        if (temp != null && temp != string.Empty)
                                        {
                                            dataArray[i, j] = temp;
                                        }
                                        temp = null;
                                    }
                                }
                                catch
                                {
                                    dataArray[i, j] = null;
                                }
                            }

                        }
                    } while (!(scrollVerticalIncrament(direction)));
                } while (!(scrollHorizontalIncrament()));

                returnArray = dataArray;
            }

Thanks in Advance!!!

Visual Basic Application to Generate Word Documents (Stopped Working?)

$
0
0

Hi we have a VB2010 application that we use to generate a selection of Word 2010 documents, which worked fine until we upgraded to Word 2013.

It appears that the application crashes while trying to set some of the oDoc.PageSetup border functions, and the oDoc.BuiltInDocumentProperties seem to have issues too, not populating the correct sections etc. however the most annoying is theoPara.Range.InsertBreak function causes an error also?

We use this application to automate generation of our test documents based on information entered by the user, project, number & type of devices etc. It generates a selection of Word and Excel documents containing a variety of pre-set test procedures, tables and spread sheets.

I've tried changing the versions of the office object libraries referenced 10.0, 14.0 & 15.0 still doesn't work?

1st question: Is there any way to fix these problems, It took us a while to get the original application working as the online samples at the time weren't that helpful?

2nd. As this application will possibly be running on a variety of differently configured systems with regards to OS XP, 7, 8 & 10  (x32-bit)(x64-bit) and the version MS Office, is there a way of detecting these and redirecting to the appropriate code if needed?

Thanks in advance

UIAutomation: Getting Row from Janus GridEx Control extremely Slow

$
0
0

It was extremely slow with Finding row from the grid that I am using (Janus.Windows.GridEX.v3.dll),OS- Windows7, 64bit, UIAutomationClient.dll Version: 4.0.0.0. I have 5000 rows in my table, and using following code to fethc a row.

AutomationElement gridElement = AutomationElement.RootElement.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, "_gridEX"));

Condition c = new PropertyCondition(
    AutomationElement.NameProperty, "Row 1000",
    PropertyConditionFlags.IgnoreCase);

AutomationElement ae = gridElement.FindFirst(
    TreeScope.Element | TreeScope.Children, c);


Help selecting/editine Word Document Section Headings in VB .Net

$
0
0

Hi I have an application that automatically generates a selection of word documents using templates & preformatted document sections which get added depending on what the user has entered into the associated data fields on the form.

  • COVER PAGE
  • INTRODUCTION
  • TABLE OF CONTENTS
  • PRE-REQUISITES
  • TEST CASES
  • RESULTS
  • SIGNATURES

Each of the above sections may contain a variety of sub-sections depending on same user entered data

  • TEST CASES
  • - TC 01
  • - TC 02
  • - TC 03

I have now been asked if it is possible to add some numbers pre heading types as some customers prefer this format?

  • 5. TEST CASES
  • 5.1 - TC 01
  • 5.2 - TC 02
  • 5.3 - TC 03

At Present the template files are using Heading 1..3 Styles which updates the Table of Contents perfectly, I'm looking for a method of parsing the finished document section by section updating the headings as required, but I can't figure out how to retrieve this info.

I'm looking for something similar to the following code :-

For each _sec in oDoc.Sections

nSec_1 += 1:nSec_2 = 0

For each _Head in _sec.???

nSec_2 += 1

_Head.Text = (nSec_1 + (nSec_2 * 0.1)).toString & vbTab & _Head.text

Next

Next

Thanks

RowsCount of the DataGridView

$
0
0

hi,

Have you any idea about how to obtain total rows count of the DataGridView Or obtaining certain properties which are not exposed in normal automation element properties?

Issue finding child controls inside WPF Group control using UIAutomation Client and UIA Verify

$
0
0

We are using WPF controls and reporting framework from DevExpress XtraReports. Housed inside a custom WPF control, there is a Group control called 'BarManager' that has two child Group controls, "BarContainerControl" and "DocumentPreviewDockLayoutManager". 

When a user first opens the reporter, all expected elements are visible. The BarContainerControl, though it is visible and all of its child controls are displayed, cannot be seen by the UIA Verify tool and attempts to automate it result in null reference exceptions.

I have attempted using FindAll, FindFirst, ControlViewWalker, and RawViewWalker to grab the BarContainerControl. The only thing that makes the BarContainerControl visible to UIA is a manual click on one of the child controls prior to automation.

Is this an issue with UIA, or is it likely to be an issue with the control authors not allowing the children to be automated until a condition is met?

Any help is appreciated.

Regards, 

A. Daly

The on screen keyboard will not appear.

$
0
0
when opening the on screen keyboard it freezes then a box opens sayin couldn't open on screen keyboard.

Preventing UI Automation access to an application

$
0
0

Hi

Congratulations of the new forum, it should be a great thing to have.

I just wanted to know -  is there a way of preventing or limitting UI Automation access to an application?

 

HOWTO Block and Enable Applications using UI-Automation.

$
0
0

Please help,

We have a desktop C#/.NET application, that uses UI-auotmation. Specifically through the Interop.UIAutomationClient, and ultikately calls such functionality as the "ElementFromPoint". How can UI-Automation be enabled/disabled from an application, like say IE11?

HOWTO Deal with UAC vs UI-Automation.

$
0
0

Please help,

We have a C#/.NET apoplication that uses Interop.UIAutomationClient, and ultimately calls such functionality as the "ElementFromPoint" (https://msdn.microsoft.com/en-us/library/windows/desktop/ee671538(v=vs.85).aspx ).

We do not know how to deal with UAC User Account Control), if it were to block "ElementFromPoint" from working.

First off, there is no documentation in that link, to explain, what kind of error we would get back, if our app were to try and use "ElementFromPoint" on say IE11. Preferably, we'd get some error, saying UAC is at fault, contact you administrator to do X, Y, Z to let our application run UI-Automation on IE11.

After that, what would be the best approach for our app, to comply better with UAC, so that some administrator could identify it, as needing UAC acccess to say IE11.

Visual Basic 2010 . Net & Microsoft Word Document

$
0
0

Hi

I am currently working on a VB . Net application (Upgrade) that I am having a few issues with.

The desktop application is a stand-alone Windows program GUI that automatically creates a selection of documents based on items ticked on the GDI

These items relate to individual document templates stored within a data folder, the templates all relate to different document sections, Cover Page, Introduction, TOC etc.

At present my application is creating the documents at a preliminary level, with all the required sections being added as required.

I now have a few modifications that I'd like to upgrade the application with...

  1. How to detect the PC has a valid copy of Microsoft Office Word installed, and what version is installed?
  2. How to detect if the document is already opened in another instance of Word before attempting to modify it, shutting it down when requested?
  3. My template sections contain several Headings, How do I implement the ability to have these headings numbered or not i.e. "Heading 1","Heading 2" or "1. Heading 1", "1.1 Heading 2"
  4. With Item 3. the headings should all be numerically correct
  5. Some sections contain tables that I'd like to populate with specific data dependant on the selections, how do I/or best method of reference tables in various different sections?

I've spent the best part of a month and  a half trawling through examples which either don't work or are VBA instead of Studio 2010 VB.net as entered?

P.S. The section headings items are my main issue at the moment, My best result so far was parsing every section in every document and manually adjusting the text, but this method takes too long to complete, I'm looking at just modifying the built in Header 1_9 settings to have leading numbers or not but cant figure out how to achieve this, recording a macro returns invalid VBA code for VB.Net?

TIA Alan

Remote Controlling WPF Window

$
0
0

Hi!

We have a situation where we need to "remote control" a WPF application, a fully separated WPF window on a Virtual Desktop.

We can start the WPF application on a virtual desktop and can send messages to it. The problem is that the mouse messages we send trigger an effect only after we switch to that desktop and move the mouse above the application.

Any help would be much apreciated!

How to get current user logon and logout time in windows 7 using VB.NET or C#

$
0
0

I want get current user logon and logout time and print them it to a Textbox. I am using VB.NET and SQL Server. Please guide me how to get this.

Thanks in advance.

How do I get the visual/window of an automation element?

$
0
0

        

I have an use case as follows,

        Process proc = Process.Start("myproc.exe");
        AutomationElement automationElement = AutomationElement.RootElement.FindFirst(TreeScope.Children,
                    new System.Windows.Automation.PropertyCondition(AutomationElement.ProcessIdProperty,
                        proc.Id));
        var imageAutomationElmt = automationElement .FindFirst
                (TreeScope.Descendants, new System.Windows.Automation.PropertyCondition
                    (AutomationElement.AutomationIdProperty, "imageData"));

        HwndSource src = HwndSource.FromHwnd(Process.GetProcessesByName("myproc")[0].MainWindowHandle);

       

I was planning to acquire the Hwnd and then Visual and render it. But HwndSource is null. I understood all WPF controls need not necessarily have a HWND. All I need is to save the control's data to a file. I am aware of screen capture, but that doesnt suit my use case, I need the actual data within my image control.  How do I render my automation element to a file?




Objects not accessibled in windows10/Internet Explorer

$
0
0

Hi,

Since we are using Windows 10, our sso software is not able to detect any object in Internet Explorer.

We have registered again the dll used for accessibility (oleacc.dll) but it change nothing at the problem.

We have dowloaded the program called accexplorer32.exe and we see that none of the objects are vsible for the soft.

Have you got an idea what's going wrong ?

How to capture and simulate the touch operations.

$
0
0

I have a WPF Application which can synchronize operation to other computer.

But now I add office control to it. I don't how to synchronize touch operations in the office control to other computer.

Is it possible to capture the touch operations in PC A and simulate these to PC B?

UI Automation API does not work well on Windows 10

$
0
0

Hi there,

We use UI Automation API to implement our automation test framework. A lot of bugs have been reporting recently by windows 10 users. Can any one provide some inputs for my questions? Thanks a lot in advance!

1. We are using .Net Framework 4.0, and the corresponding UI API version is 3.0, correct? And 3.0 is the latest version?
2. Are there any improvements/changes for UI API to better support windows 10.
3. In case any UI Automation API issues on windows 10, where/how should I report them?

Regards,
Chad


UI automation on mouse over draw a rectangle C#

$
0
0
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace zee.Views
{
/// <summary>
/// Interaction logic for Inspector.xaml
/// </summary>
public partial class Inspector : System.Windows.Controls.UserControl
{


    #region Win32 API Declarations

    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct POINT
    {
        public int X;
        public int Y;

        #region Helper methods

        public POINT(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }

        public static implicit operator System.Drawing.Point(POINT p)
        {
            return new System.Drawing.Point(p.X, p.Y);
        }

        public static implicit operator POINT(System.Drawing.Point p)
        {
            return new POINT(p.X, p.Y);
        }

        #endregion
    }

    const int DSTINVERT = 0x00550009;

    [DllImport("gdi32.dll")]
    static extern bool PatBlt(IntPtr hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, uint dwRop);

    [DllImport("user32.dll")]
    static extern IntPtr WindowFromPoint(POINT Point);

    [DllImport("user32.dll")]
    static extern int GetWindowText(int hWnd, StringBuilder text, int count);

    [DllImport("user32.dll")]
    static extern IntPtr GetWindowDC(IntPtr hWnd);

    [DllImport("user32.dll")]
    static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

    [DllImport("user32.dll")]
    static extern bool OffsetRect(ref RECT lprc, int dx, int dy);

    [DllImport("user32.dll")]
    static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

    [DllImport("user32.dll")]
    static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);

    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(out System.Drawing.Point lpPoint);

    [DllImport("User32.dll")]
    static extern IntPtr GetDC(IntPtr hwnd);

    [DllImport("gdi32.dll")]
    static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

    [DllImport("user32.dll")]
    static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);


    #endregion

    bool _dragging;
    IntPtr _hWndCurrent;
    System.Windows.Input.Cursor _curCross;
    System.Drawing.Image _imgAppCross;
    System.Drawing.Image _imgApp;

    public Inspector()
    {
        InitializeComponent();
        Assembly assembly = Assembly.GetExecutingAssembly();
        _imgAppCross = System.Drawing.Image.FromStream(assembly.GetManifestResourceStream("zee.Assets.Images.app_cross.png"));
        _imgApp = System.Drawing.Image.FromStream(assembly.GetManifestResourceStream("zee.Assets.Images.app.png"));
        _curCross = new System.Windows.Input.Cursor(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Assets\\Images\\cross.cur"));
        dragPictureBox.Image = _imgAppCross;
    }

    private System.Drawing.Point ConvertPixelsToUnits(double x, double y)
    {
        // get the system DPI
        IntPtr dDC = GetDC(IntPtr.Zero); // Get desktop DC
        int dpi = GetDeviceCaps(dDC, 88);
        bool rv = ReleaseDC(IntPtr.Zero, dDC);

        // WPF's physical unit size is calculated by taking the
        // "Device-Independant Unit Size" (always 1/96)
        // and scaling it by the system DPI
        double physicalUnitSize = (1d / 96d) * (double)dpi;
        System.Drawing.Point wpfUnits = new System.Drawing.Point(Convert.ToInt32(physicalUnitSize * (x)),Convert.ToInt32(physicalUnitSize * (y)));

        return wpfUnits;
    }
    public POINT GetCursorPosition()
    {
        System.Drawing.Point lpPoint, wpfPoint= new System.Drawing.Point();

        if(GetCursorPos(out lpPoint))
        {
             wpfPoint = ConvertPixelsToUnits(lpPoint.X, lpPoint.Y);
        }
        //bool success = User32.GetCursorPos(out lpPoint);
        // if (!success)

        return wpfPoint;
    }
    private void DrawRevFrame(IntPtr hWnd)
    {
        if (hWnd == IntPtr.Zero)
            return;

        IntPtr hdc = GetWindowDC(hWnd);
        RECT rect;
        GetWindowRect(hWnd, out rect);
        OffsetRect(ref rect, -rect.Left, -rect.Top);

        const int frameWidth = 3;

        PatBlt(hdc, rect.Left, rect.Top, rect.Right - rect.Left, frameWidth, DSTINVERT);
        PatBlt(hdc, rect.Left, rect.Bottom - frameWidth, frameWidth,-(rect.Bottom - rect.Top - 2 * frameWidth), DSTINVERT);
        PatBlt(hdc, rect.Right - frameWidth, rect.Top + frameWidth, frameWidth,rect.Bottom - rect.Top - 2 * frameWidth, DSTINVERT);
        PatBlt(hdc, rect.Right, rect.Bottom - frameWidth, -(rect.Right - rect.Left),frameWidth, DSTINVERT);
    }

    private string GetWindowText(IntPtr hWnd)
    {
        StringBuilder text = new StringBuilder(256);
        if (GetWindowText(hWnd.ToInt32(), text, text.Capacity) > 0)
        {
            return text.ToString();
        }

        return String.Empty;
    }

    private string GetClassName(IntPtr hWnd)
    {
        StringBuilder className = new StringBuilder(100);
        if (GetClassName(hWnd, className, className.Capacity) > 0)
        {
            return className.ToString();
        }

        return String.Empty;
    }

    private string GetApplication(IntPtr hWnd)
    {
        int procId;
        GetWindowThreadProcessId(hWnd, out procId);
        Process proc = Process.GetProcessById(procId);
        return proc.MainModule.ModuleName;
    }

    private void dragPictureBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            _dragging = true;
            Assembly assembly = Assembly.GetExecutingAssembly();
            System.Windows.Input.Mouse.OverrideCursor = _curCross;
            dragPictureBox.Image = _imgApp;
        }
    }

    private void dragPictureBox_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (_dragging)
        {
            _dragging = false;
            System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
            if (_hWndCurrent != IntPtr.Zero)
            {
                DrawRevFrame(_hWndCurrent);
                _hWndCurrent = IntPtr.Zero;
                // The image in the dragPictureBox will be restored when the context menu is closed
            }
            else
            {
                dragPictureBox.Image = _imgAppCross;
            }
            dragPictureBox.Image = _imgAppCross;
        }
    }

    private void dragPictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (_dragging)
        {
            IntPtr hWnd = WindowFromPoint(GetCursorPosition());
            if (hWnd == dragPictureBox.Handle)
            {
                // Drawing a border around the dragPictureBox (where we start
                // dragging) doesn't look nice, so we ignore this window
                hWnd = IntPtr.Zero;
            }

            if (hWnd != _hWndCurrent)
            {
                if (_hWndCurrent != null)
                {
                    DrawRevFrame(_hWndCurrent);
                }
                DrawRevFrame(hWnd);
                _hWndCurrent = hWnd;
            }

            if (hWnd != IntPtr.Zero)
            {
                txtWindowHandle.Text = hWnd.ToString();
                txtWindowText.Text = GetWindowText(hWnd);
                txtClassName.Text = GetClassName(hWnd);
                txtApplication.Text = GetApplication(hWnd);
            }
            else
            {
                txtWindowHandle.Text = String.Empty;
                txtWindowText.Text = String.Empty;
                txtClassName.Text = String.Empty;
                txtApplication.Text = String.Empty;
            }
        }
    }
 }

So this is my code for control inspector in windows<strike>  </strike>. It works almost fine<strike> </strike>for winforms  , my problem is when i am trying to inspect a wpf or windows 10 // or website in browser  , it is unable to inspect 

Not getting correct caret position of textbox of webpage in chrome using wpf C#

$
0
0

I have built a wpf application to capture screens. Captured screen details are collected from System accessible object which is created from caret position using GUITHREADINFO. It is working fine in IE and firfox browser, but not getting correct caret position while capturing screen in chrome browser and hence incorrect System accessible object. Can somebody help why it is not working while capturing screen in chrome browser. I have shared code snippet here. Any help would be most appreciated. Thanks.

SystemAccessibleObject sao = null;

GUITHREADINFO guiInfo;
        Point caretPosition;
        public void GetCaretPosition()
        {
            guiInfo = new GUITHREADINFO();
            guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);

            // Get GuiThreadInfo into guiInfo
            GetGUIThreadInfo(0, out guiInfo);
        }

caretPosition = new Point();

                        // Fetch GUITHREADINFO
                        GetCaretPosition();

                        caretPosition.X = (int)guiInfo.rcCaret.Location.X;
                        caretPosition.Y = (int)guiInfo.rcCaret.Location.Y;

ClientToScreen(guiInfo.hwndCaret, out caretPosition);

sao = SystemAccessibleObject.FromPoint(caretPosition.X, caretPosition.Y);

Viewing all 585 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>