Reputation: 11
I'm using the AutomationElement-Class to find a chat in a flash application (BigBlueButton, http://demo.bigbluebutton.org, I'm testing it there) in a browser (firefox). It seems to work as long as no new messages appear. Every time a new Message comes in, the UI updates the AutomationElement which a) can't find the chat or b) the AutomationElement describes the chat contains no messages. Before a new message arrives it seems to work. I can access the messages.
My Code so far:
private void getLastChatMessage(){
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("Firefox");
AutomationElement au = AutomationElement.FromHandle(p[0].MainWindowHandle);
PropertyCondition chatCond = new PropertyCondition(AutomationElement.NameProperty, "Message Box");
Condition listCond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List);
AndCondition listAChatCond = new AndCondition(listCond, chatCond);
AutomationElement chatArea = au.FindFirst(TreeScope.Descendants, listAChatCond);
if (chatArea == null)
{
System.Console.WriteLine("chatArea == null");
return;
}
System.Console.WriteLine("name: {0}", chatArea.Current.Name);
PropertyCondition messageCond = new PropertyCondition(AutomationElement.IsEnabledProperty, true);
AutomationElementCollection chatMessages = chatArea.FindAll(TreeScope.Children, messageCond);
if (chatMessages.Count > 0)
{
String lastMessage = chatMessages[chatMessages.Count - 1].Current.Name;
System.Console.WriteLine("lastMessage: {0}", lastMessage);
}
else
{
System.Console.WriteLine("chatMessages.Count <= 0");
}
}
Has anybody an idea how to get the chat after a UI update?
I tested it with the MS inspect-tool (https://msdn.microsoft.com/en-us/library/windows/desktop/dd318521%28v=vs.85%29.aspx). If a new chat message comes in and I refresh the tree I also didn't see the new message. The same happens if I'm testing this with the internet explorer. If I'm collapsing the whole tree of the application and the I go again to the messages I see the new message. Sometimes I can't see the whole tree after I have collapsed the tree. Then I have to restart the browser. Does anybody know how I can get the new message whit my program? How (and why) does the inspect-tool get better results?
Greetings
Upvotes: 1
Views: 68