This project is read-only.

how to select an item from WPFTextBlock

Oct 13, 2010 at 2:48 PM

Hello,  have a WPF text block which consist an item , however UI spy does not recognize the item at all. How should i go about clicking this object (item)? Has anyone had the same scenario? Any suggestions? Thanks in advance.

Oct 13, 2010 at 4:27 PM


if UI Spy don't see it ,not visible for UIAutomation, and not for White

clicking only by position relativ to parent object.

or, ask developer to imlement automation peer for this element.


Oct 13, 2010 at 9:21 PM

Thanks Throndorin. I have actually used the Raw view of the UI spy and able to see this element in UI spy. The classname is "TextBlock" and the automationid is TextBlock2. I also see the name given. Do you think it is possible to click on this element or i still will have to approach the development team in regards to the implementation of Automation peer.? Can you please confirm. Thanks.

Oct 13, 2010 at 11:08 PM




no, if ui spy can found it UIAutomation can also find the element, no need for the developer to become active.


Why do y want to click on a label?


The way how to get it if normal White way not work;


You have a Label in a Label , and White only find the parent label, correct?



Label parent = window.Get.......;

AutomationElement inner = parent.GetElement(SearchCritera.ByAutomationId("TextBlock2");

Label innerLabel = new Label (inner, parent.ActionListener);









Oct 14, 2010 at 3:11 AM
Edited Oct 14, 2010 at 3:40 AM

Sorry posted the query in the wrong place

Oct 14, 2010 at 3:21 AM

Hello Throndorn,

I have a question in regards to the solution you provided. The hierarchy for the element is MainWindow --then Window (which has class popup) -- text "create new" which has class TextBlock. I am not sure what would be hte parent label here. Please help. Thanks.

Oct 14, 2010 at 7:43 AM



oh I think I misunderstud your first explanation :)

the parent element in your case is a menu item

so the menu item has a  label as element.


the best way is to follow the hierarchy



//if menu item has automatio ID

Menu menu = mainwindow.Popup.Items().Where (p=>p.AutomationElement.Current.AutomatioID == "id").First();

// if menu item does not have automation ID

Menu menu = mainwindow.Popup.Items().Where (p=>p.Name == "create new").First();

Label label = menu.Get<Label>(SearchCritera.ByAutomationId("TextBlock2"));



if this don't work fallback to the AutomationElement solution with menu as parent.




Oct 14, 2010 at 12:56 PM

Hi Throndorin,

Sorry for taking your time but i am kind of lost here.  How do go by using menu item here. Actually eventhough i see the window has a popup class (this is howi see in the UI Spy) however the way it is displayed in GUI is : I have a Combo Box which is invoked by clicking and there are 5 list items in the combobox (which are recognized) then there is a horizontal scrollbar and after the scroll bar I have an  item (TextBlock) on which i want to perform a click action. I am sorry about not explaining it right. Actually I got confused myself. Do you think it can still work with thesolution provided above. If so, how do i do it. Thanks again .

Oct 14, 2010 at 1:14 PM




can you link a screenshot here?



Oct 14, 2010 at 3:09 PM

How do i link a screenshot here?

Oct 14, 2010 at 3:16 PM

I have tried to add the Screenshot

This is the screeshot of the UI spy here



Oct 14, 2010 at 9:18 PM
sonia123 wrote:

I have tried to add the Screenshot

This is the screeshot of the UI spy here




you can't add picures directly here :(  use a side where you can host them like Imageshack , or enable mailing in your profile so I can send you my mailaddress.



Oct 15, 2010 at 1:56 AM
Edited Oct 15, 2010 at 3:47 AM

Hello Throndorin. I really appreciate your help on this issue.

The link to the screenshot is It contains:


--Window  (main window)

  --- Window


            -----listitems --> I can access all list items which are part of a combo box

    --- text    -->  This is of class TextBlock where i am having problem.



let me know if this  is not clear. My email address is I will send you the screenshot onice i get ur mail address. Once again, i really appreciate your patience, time and help on this. Thanks.

Oct 15, 2010 at 8:10 AM





AutomationElement element = window.GetElement(SearchCritera.ByAutomationId("TextBlock2"));

Label label = new Label(element, window.ActionListener);


you can also try get element from pane.