get Tooltip text

Aug 3, 2010 at 9:15 AM
Hi

The last days I tried to get the tooltip text in my application but the approach via window.Tooltip didn't work at all, all it did was returning null pointers.
So I digged a little deeper and found that the tooltip actually is a new modal popup window. I use .NET 4.0, maybe they changed something so that the tooltip is no direct child anymore (maybe it was in previous versions or WinForms?!). Anyway, window.Tooltip doesn't work for me and I can't find the tooltip by its automation id either. looking in the opened modal window is the only working way for me.
I post the code below, maybe it's helpful for other people and/or further development of white. My implementation is far from perfect, it just works in my environment and most likely needs adjustments in other applications.

White.Core.UIItems.WindowItems.Window childWindow = ActiveWindow.ModalWindow(""); //ActiveWindow capsulates the retrieval of the main window; search for a modal window without a name, that's the tooltip.
string tooltip = childWindow.Get<WPFLabel>(SearchCriteria.ByAutomationId("ai_ToolTip1")).Text; //I used a textblock for my tooltip. more sophiticated tooltips may not want to limit their search to WPFLabel.

Coordinator
Aug 6, 2010 at 6:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 21, 2010 at 10:41 AM

Hi

here a short workaround if there is standard ToolTip (WPF)

 

/// <summary>
/// Gets the tool tip text.
/// </summary>
/// <returns></returns>
public static string GetToolTipText(Window window)
{
  AutomationElement element = window.AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolTip));

  ToolTip toolTip = new ToolTip(element, window.ActionListener); //I used a textblock for my tooltip. more sophiticated tooltips may not want to limit their search to WPFLabel.
  return toolTip.Text;
}

Throndorin