1
Vote

Get-UiaEdit failed to get control

description

Note that here UIA is used instead of ComObject "internetExplorer.Application"

because windows popups started by some webs are to be managed

Import-Module UIAutomation

starting I.E 8 on Win2003

$prc = Start-Process 'C:\Program Files\Internet Explorer\iexplore.exe' -PassThru

BUG : $prc.ID is wrong when another I.E window is already open

sleep -Seconds 2;

$wnd = Get-UiaWindow -pid $prc.Id

test.htm contains :

<html>

<body>

<table class="UsernamePasswordTable">

<tr><td>DAS ID: </td><td><input name="tb1" type="text" id="id1" /></td></tr>

<tr><td>Password: </td><td><input name="tb2" type="text" id="id2" /></td></tr>

</table>

</body>

</html>

$wnd | Get-UIAEdit -name 'Address' | Set-UIAEditText 'test.htm'

$wnd | Get-UIAButton -name "test" | Invoke-UIAButtonClick

$td = $wnd | Get-UIAText -name 'DAS ID: '

$tr = $td | Get-UIAControlParent

$table = $tr | Get-UIAControlParent

put OK from <TABLE> object but into both fields

$table | Get-UIAEdit | Set-UIAEditText 'set from table'

text field is accessible from the TR object

($tr | Get-UIAtext).Current.Name

but Edit field is not accessible from <TR> object

$tr | Get-UIAEdit | Set-UIAEditText 'set from tr'

BUG => Get-UiaEdit : failed to get control in 5000 milliseconds by: title: '', automationId: '', className: '', value: ''.

file attachments

comments

apetrovskiy wrote Mar 18, 2014 at 6:30 PM

Hi,
first of all about the Start-Process cmdlet. Some applications run something like 'engine' that in turn runs the app itself. For example, mmc.exe 32-bit on 64-bit Windows. I suspect that IE works similarly: it has a starter executable and the browser tab window.
Anyway, please don't address problem with the Start-Process cmdlet to me - thi is Microsoft's I can't fix it. :)

Now about the code - I'm on Windows 8 64-bit now with IE10 and I hope that latest IEs work more or less in a similar fashion. This code works for me (attached), UIAutomation 0.8.7 Beta 2:
# your test file c:\1\test.htm

[int]$id = 123
[string]$password = "pwd"

# browsers usually accept path to an html file as input
Start-Process iexplore -ArgumentList "C:\1\test.htm" -PassThru
# just got the sleep from your code
sleep -Seconds 2
# to be sure that the window contains necessary controls, there is the -WithControl parameter
# however, always work with as less windows as possible
$wnd = Get-UiaWindow -ProcessName iexplore -WithControl @{contorlType="edit";class="edit"},@{controlType="text";name="das*"},@{controlType="text";name="pass*"}

# you don't need the table
# $table = $wnd | Get-UIAText -name DAS* | Get-UIAControlParent | Get-UIAControlParent

# instead, go up to the custom objects that are parents of the text boxes and get their siblings respectively:
Get-UIAText -name DAS* | Get-UIAControlParent | Get-UIAControlNextSibling | Get-UiaEdit | Set-UiaEditText $id
Get-UIAText -name pass* | Get-UIAControlParent | Get-UIAControlNextSibling | Get-UiaEdit | Set-UiaEditText $password
My IE 10 runs 2 process on the first start and adds one more process on every next time I run the Start-Process cmdlet.

Regarding the buf with Get-UiaEdit. I don't know what set of controls is seen in IE 8, in IE 10 I have for every pair of controls (text + edit) the following:

table - another custom - edit
|
custom
|
text
This explains how the edit is accessible from the table and inaccessible from the custom that is over the text.

apetrovskiy wrote Mar 18, 2014 at 6:31 PM

attachment

PORCHEROT wrote Mar 19, 2014 at 12:53 PM

Hi, Many thanks for the quick workaround, which is also working on IE8