Forum Discussion
Hi ,
Find the label and get width and height
For example
TreeView.Click(label.width+10/2,label.Height/2);
another way,
Place selection on TreeItem,Press Space Key [Space],it will expand.
Regards,
Karthick Raj P
Hi,
can you tell me what you mean by label and treeview (which objects)
I tried something similar
On Error Resume Next strLongName = func_RetrieveLongName(Driver2)
' here from "func_RetrieveLongName"
I am getting the full of the object from a excel sheet as I am doing this as data driven, that full name is
Sys.Browser("iexplore").Page("*").Panel(1).Panel(0).Panel(0).Panel(1).Panel(0).Panel(0).Panel(0).Panel(0).Panel(1) |
panel(1) in having only one child i.e for the "Routine" label as panel(0) (attached image img.PNG)
Set Obj = eval(strLongName) Dim x,y x = Obj.Left + Obj.Width / 2 y = Obj.Top + Obj.Height / 2 ' Obtains the IMG object by coordinates Set a= Sys.Desktop.ObjectFromPoint(x, y) If a.Exists Then a.Click Else Call Log.Warning("Unable to simulate the click.") End If If Err.Number > 0 Then Log.Message Err.Description End if
for the a.click action I am getting message "waiting until the overlapped window becomes visible"
as my tree view in on the Modual Dialogue Box
so i guess I need to get the coordinates of that dialogue box I am not sure how to get them any idea on this?
and is the code i have written correct?
thanks,
Amey
- Colin_McCrae8 years agoCommunity Hero
Close.
Hard to say what's happening exactly as I'm not sure exactly which object you are passing your function. But you are using the wrong information, and clicking in the wrong place. You're also trying to interpret and object by moving the mouse to it and getting the object under the mouse at that point? If there are overlays and things in place, that could all go horribly wrong.
Anyway.
Using the example here: http://www.jqueryrain.com/?KIVkhqxl
As it looks most similar to yours. (But may not be. It looks like there are various ways of building these and this looks closer than the other example I found.)
This code (VBScript - which is what you're using by the look of it):
Function ClickNode() Dim searchPROP(1) Dim searchVAL(1) searchPROP(0) = "contentText" searchPROP(1) = "className" searchVAL(0) = "root2*" searchVAL(1) = "node-wrapper" Set tree = Sys.Browser("iexplore").Page("http://www.jqueryrain.com/?KIVkhqxl").Frame(0).Panel(0).Panel(0).Panel(0).Panel(0).Panel(0).Panel(1).Panel(1).Panel(0).Panel(1).Panel(0).Panel(0).Panel(3).Panel(0).Panel(0).Panel(0).Panel(0).Panel(0).Frame(0).Panel(0) Set node = tree.FindChild(searchPROP, searchVAL, 2) y = node.Height / 2 x = 4 node.Click x,y End Function
Will expand/contract the second node in tree on that example page.
It's simple enough.
Assigns the tree container to an object.
Searches for the node it wants within the tree using the content text and class name. You have to use two parameters to make sure you get the single line. If you don't, and search using text only, it will find the container wrapper for the entire node (including child nodes if it's open) and the co-ordinates could be wrong (they'll be wrong if the node is expanded). You have to isolate it to the single line within the node. With a "*" in the text search part as it's only the first, main text, part I'm after.Assigns that to an object.
Gets the height of the node and divides by 2 to get the mid-point.
Don't need the width as we know it's the little arrow on the left we want to click so it's hard-coded to 4.The height on this is example is 29. So call it 15 once divided by 2.
It then applies the Click on the node it found at point 4 , 15 within the object. So 4 pixels in halfway up.
And the node expands. Or contracts. Depending what state it's currently in. (You can also check that.)
If you change the text search string to "asyncroot*", it will do the same to the third node. Etc etc.
You would need to add to this. Pass in parameters. Add some error handling. Put it in some sort of stepped loop if you need to go several levels deep. But this demonstrates the basics of clicking a single node. Open the sample I linked to in IE and try it. (Should work in Chrome as well but it looks like Chrome updated itself last night and I'm going to have to update or patch my TestComplete install to get it working again. Sigh.)
- ameykhopade8 years agoContributor
thanks alot.
this should definitely work.
can you just tell me what kind of check should I do to check if the node is currently expanded or not.
thanks,
amey
- Colin_McCrae8 years agoCommunity Hero
Again, using the jqueryrain.com example ...
You need to look at the top level container for the node.
To find the expander, you need to find the node line. The node line is contained within a wrapper for the node overall.
So the structure is:
1 Tree > 1+ Nodes > 1+ Node Lines (well, line wrapper - as it encompasses text, button, etc) - and this can continue down with Node Lines containing further Nodes if they are also expandable.
So from the node line my sample code finds, you would need to go up the hierarchy to find it's parent container. This will have the class "tree-node-*" (* being a wildcard) .... with a variable number of sub-classes after it. First of which is "expanded" (if the node is open) or "collapsed" (if the node is closed). But be careful how you interpret the classes as it adds additional sub-classes if the node is focussed, highlighted, etc etc. There are quite a lot of status sub-classes that can be applied.
But if you find the single line. You can just parent your way up until you hit the "tree-node*" and then check the content of it's full classname to work out what else is going on.
Not sure how that applies to child nodes (which can also expand and collapse) but it will be something similar using sub-classes I would imagine.
You're going to need to build a fairly complex little handler routine to make this fully controllable. Especially if it may have to expand it's way several levels deep. But it's do-able. :)