UI Automation: Open File dialog elements tree contains not all elements
I'm trying to use UI Automation with C# to type file path in opened Open
dialog and then press Open button. I'm able to find the dialog itself, but searching for inner elements (file path text box and Open button) gives no result. When I traverse elements tree writing elements to log file, I see that the log is obviously too short and not all elements printed out.
Strange behavior: if I switch with mouse on another window, traversing of the dialog returns all elements and I'm able to find desired controls and interact with them.
I've tried many approaches to bypass the problem:
- open some window, switch to it with
AutomationElement.SetFocus
; - search for element with Win API (
FindWindowEx
); - get
AutomationElement
by point on screen within dialog's bounding rectangle iterating by x and y with some step.
No one approach give me desired result.
What can cause incomplete elements tree using UI Automation and what is workaround for this?
My scenario is:
- test clicks on a button on web page
- standard Windows dialog to select a file is opened
- I'm trying to fill file path text box and press Open button using UI Automation
c# ui-automation
|
show 3 more comments
I'm trying to use UI Automation with C# to type file path in opened Open
dialog and then press Open button. I'm able to find the dialog itself, but searching for inner elements (file path text box and Open button) gives no result. When I traverse elements tree writing elements to log file, I see that the log is obviously too short and not all elements printed out.
Strange behavior: if I switch with mouse on another window, traversing of the dialog returns all elements and I'm able to find desired controls and interact with them.
I've tried many approaches to bypass the problem:
- open some window, switch to it with
AutomationElement.SetFocus
; - search for element with Win API (
FindWindowEx
); - get
AutomationElement
by point on screen within dialog's bounding rectangle iterating by x and y with some step.
No one approach give me desired result.
What can cause incomplete elements tree using UI Automation and what is workaround for this?
My scenario is:
- test clicks on a button on web page
- standard Windows dialog to select a file is opened
- I'm trying to fill file path text box and press Open button using UI Automation
c# ui-automation
When you have found theAutomationElement
(corresponding to the new Window), you can useFindAll()
to find a specific class and cast it toAutomationElement
. Something like:AutomationElement element = [MainElement].FindAll(TreeScope.Descendants, Automation.RawViewCondition).OfType<AutomationElement>().FirstOrDefault(elm => elm.Current.ClassName.Contains("[Some Class Name]"));
– Jimi
Nov 13 '18 at 12:18
Yes, but problem is elements are not found due to internal elements tree is incomplete for some reason
– Maxim
Nov 13 '18 at 12:23
They're probably just inside a different container. If you don't know the structure of the Dialog you're inspecting, use Spy++ to explore it, see what the nesting is and act on it. When you have a better view of the Dialog composition, its easier to get to the right elements while parsing the Tree. You'ld have the same problem if you were usingEnumChildWindows
.
– Jimi
Nov 13 '18 at 12:27
I've inspected structure with inspectors and I see elements I need. As I wrote in my question, if I just switch to another window (while Open dialog is opened), elements are found. Also I print all structure recursively to log and don't see those elements. So there is no problem with how I search for them.
– Maxim
Nov 13 '18 at 12:29
What is this Dialog? Is it the Shell'sBrowseForFolder
one?
– Jimi
Nov 13 '18 at 12:31
|
show 3 more comments
I'm trying to use UI Automation with C# to type file path in opened Open
dialog and then press Open button. I'm able to find the dialog itself, but searching for inner elements (file path text box and Open button) gives no result. When I traverse elements tree writing elements to log file, I see that the log is obviously too short and not all elements printed out.
Strange behavior: if I switch with mouse on another window, traversing of the dialog returns all elements and I'm able to find desired controls and interact with them.
I've tried many approaches to bypass the problem:
- open some window, switch to it with
AutomationElement.SetFocus
; - search for element with Win API (
FindWindowEx
); - get
AutomationElement
by point on screen within dialog's bounding rectangle iterating by x and y with some step.
No one approach give me desired result.
What can cause incomplete elements tree using UI Automation and what is workaround for this?
My scenario is:
- test clicks on a button on web page
- standard Windows dialog to select a file is opened
- I'm trying to fill file path text box and press Open button using UI Automation
c# ui-automation
I'm trying to use UI Automation with C# to type file path in opened Open
dialog and then press Open button. I'm able to find the dialog itself, but searching for inner elements (file path text box and Open button) gives no result. When I traverse elements tree writing elements to log file, I see that the log is obviously too short and not all elements printed out.
Strange behavior: if I switch with mouse on another window, traversing of the dialog returns all elements and I'm able to find desired controls and interact with them.
I've tried many approaches to bypass the problem:
- open some window, switch to it with
AutomationElement.SetFocus
; - search for element with Win API (
FindWindowEx
); - get
AutomationElement
by point on screen within dialog's bounding rectangle iterating by x and y with some step.
No one approach give me desired result.
What can cause incomplete elements tree using UI Automation and what is workaround for this?
My scenario is:
- test clicks on a button on web page
- standard Windows dialog to select a file is opened
- I'm trying to fill file path text box and press Open button using UI Automation
c# ui-automation
c# ui-automation
edited Nov 13 '18 at 13:20
Maxim
asked Nov 13 '18 at 12:04
MaximMaxim
8281718
8281718
When you have found theAutomationElement
(corresponding to the new Window), you can useFindAll()
to find a specific class and cast it toAutomationElement
. Something like:AutomationElement element = [MainElement].FindAll(TreeScope.Descendants, Automation.RawViewCondition).OfType<AutomationElement>().FirstOrDefault(elm => elm.Current.ClassName.Contains("[Some Class Name]"));
– Jimi
Nov 13 '18 at 12:18
Yes, but problem is elements are not found due to internal elements tree is incomplete for some reason
– Maxim
Nov 13 '18 at 12:23
They're probably just inside a different container. If you don't know the structure of the Dialog you're inspecting, use Spy++ to explore it, see what the nesting is and act on it. When you have a better view of the Dialog composition, its easier to get to the right elements while parsing the Tree. You'ld have the same problem if you were usingEnumChildWindows
.
– Jimi
Nov 13 '18 at 12:27
I've inspected structure with inspectors and I see elements I need. As I wrote in my question, if I just switch to another window (while Open dialog is opened), elements are found. Also I print all structure recursively to log and don't see those elements. So there is no problem with how I search for them.
– Maxim
Nov 13 '18 at 12:29
What is this Dialog? Is it the Shell'sBrowseForFolder
one?
– Jimi
Nov 13 '18 at 12:31
|
show 3 more comments
When you have found theAutomationElement
(corresponding to the new Window), you can useFindAll()
to find a specific class and cast it toAutomationElement
. Something like:AutomationElement element = [MainElement].FindAll(TreeScope.Descendants, Automation.RawViewCondition).OfType<AutomationElement>().FirstOrDefault(elm => elm.Current.ClassName.Contains("[Some Class Name]"));
– Jimi
Nov 13 '18 at 12:18
Yes, but problem is elements are not found due to internal elements tree is incomplete for some reason
– Maxim
Nov 13 '18 at 12:23
They're probably just inside a different container. If you don't know the structure of the Dialog you're inspecting, use Spy++ to explore it, see what the nesting is and act on it. When you have a better view of the Dialog composition, its easier to get to the right elements while parsing the Tree. You'ld have the same problem if you were usingEnumChildWindows
.
– Jimi
Nov 13 '18 at 12:27
I've inspected structure with inspectors and I see elements I need. As I wrote in my question, if I just switch to another window (while Open dialog is opened), elements are found. Also I print all structure recursively to log and don't see those elements. So there is no problem with how I search for them.
– Maxim
Nov 13 '18 at 12:29
What is this Dialog? Is it the Shell'sBrowseForFolder
one?
– Jimi
Nov 13 '18 at 12:31
When you have found the
AutomationElement
(corresponding to the new Window), you can use FindAll()
to find a specific class and cast it to AutomationElement
. Something like: AutomationElement element = [MainElement].FindAll(TreeScope.Descendants, Automation.RawViewCondition).OfType<AutomationElement>().FirstOrDefault(elm => elm.Current.ClassName.Contains("[Some Class Name]"));
– Jimi
Nov 13 '18 at 12:18
When you have found the
AutomationElement
(corresponding to the new Window), you can use FindAll()
to find a specific class and cast it to AutomationElement
. Something like: AutomationElement element = [MainElement].FindAll(TreeScope.Descendants, Automation.RawViewCondition).OfType<AutomationElement>().FirstOrDefault(elm => elm.Current.ClassName.Contains("[Some Class Name]"));
– Jimi
Nov 13 '18 at 12:18
Yes, but problem is elements are not found due to internal elements tree is incomplete for some reason
– Maxim
Nov 13 '18 at 12:23
Yes, but problem is elements are not found due to internal elements tree is incomplete for some reason
– Maxim
Nov 13 '18 at 12:23
They're probably just inside a different container. If you don't know the structure of the Dialog you're inspecting, use Spy++ to explore it, see what the nesting is and act on it. When you have a better view of the Dialog composition, its easier to get to the right elements while parsing the Tree. You'ld have the same problem if you were using
EnumChildWindows
.– Jimi
Nov 13 '18 at 12:27
They're probably just inside a different container. If you don't know the structure of the Dialog you're inspecting, use Spy++ to explore it, see what the nesting is and act on it. When you have a better view of the Dialog composition, its easier to get to the right elements while parsing the Tree. You'ld have the same problem if you were using
EnumChildWindows
.– Jimi
Nov 13 '18 at 12:27
I've inspected structure with inspectors and I see elements I need. As I wrote in my question, if I just switch to another window (while Open dialog is opened), elements are found. Also I print all structure recursively to log and don't see those elements. So there is no problem with how I search for them.
– Maxim
Nov 13 '18 at 12:29
I've inspected structure with inspectors and I see elements I need. As I wrote in my question, if I just switch to another window (while Open dialog is opened), elements are found. Also I print all structure recursively to log and don't see those elements. So there is no problem with how I search for them.
– Maxim
Nov 13 '18 at 12:29
What is this Dialog? Is it the Shell's
BrowseForFolder
one?– Jimi
Nov 13 '18 at 12:31
What is this Dialog? Is it the Shell's
BrowseForFolder
one?– Jimi
Nov 13 '18 at 12:31
|
show 3 more comments
1 Answer
1
active
oldest
votes
I finally came to this workaround:
- the dialog is opened with textbox focused, so get handle to currently focused control;
- get
AutomationElement
by the handle; - send Alt + O using
SendKeys.SendWait
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280665%2fui-automation-open-file-dialog-elements-tree-contains-not-all-elements%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I finally came to this workaround:
- the dialog is opened with textbox focused, so get handle to currently focused control;
- get
AutomationElement
by the handle; - send Alt + O using
SendKeys.SendWait
.
add a comment |
I finally came to this workaround:
- the dialog is opened with textbox focused, so get handle to currently focused control;
- get
AutomationElement
by the handle; - send Alt + O using
SendKeys.SendWait
.
add a comment |
I finally came to this workaround:
- the dialog is opened with textbox focused, so get handle to currently focused control;
- get
AutomationElement
by the handle; - send Alt + O using
SendKeys.SendWait
.
I finally came to this workaround:
- the dialog is opened with textbox focused, so get handle to currently focused control;
- get
AutomationElement
by the handle; - send Alt + O using
SendKeys.SendWait
.
answered Nov 14 '18 at 15:12
MaximMaxim
8281718
8281718
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280665%2fui-automation-open-file-dialog-elements-tree-contains-not-all-elements%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
When you have found the
AutomationElement
(corresponding to the new Window), you can useFindAll()
to find a specific class and cast it toAutomationElement
. Something like:AutomationElement element = [MainElement].FindAll(TreeScope.Descendants, Automation.RawViewCondition).OfType<AutomationElement>().FirstOrDefault(elm => elm.Current.ClassName.Contains("[Some Class Name]"));
– Jimi
Nov 13 '18 at 12:18
Yes, but problem is elements are not found due to internal elements tree is incomplete for some reason
– Maxim
Nov 13 '18 at 12:23
They're probably just inside a different container. If you don't know the structure of the Dialog you're inspecting, use Spy++ to explore it, see what the nesting is and act on it. When you have a better view of the Dialog composition, its easier to get to the right elements while parsing the Tree. You'ld have the same problem if you were using
EnumChildWindows
.– Jimi
Nov 13 '18 at 12:27
I've inspected structure with inspectors and I see elements I need. As I wrote in my question, if I just switch to another window (while Open dialog is opened), elements are found. Also I print all structure recursively to log and don't see those elements. So there is no problem with how I search for them.
– Maxim
Nov 13 '18 at 12:29
What is this Dialog? Is it the Shell's
BrowseForFolder
one?– Jimi
Nov 13 '18 at 12:31