Page 1 of 1
Loop/Click Inner Text
Posted: Mon Sep 17, 2012 8:03 pm
by regex
Click InnerText from Column headings (they are really tricky to click).
I have this already:
Code: Select all
public void verifyDesc()
{
var table = table;
IList<Ranorex.ThTag> myList = table.FindDescendants<Ranorex.ThTag>();
foreach(Ranorex.ThTag tag in myList )
{
tag.Click();
Delay.Milliseconds(5000);
tag.Click();
}
I thought this would work but it doesn't quite
:
Code: Select all
public void verifyDesc()
{
var table = table;
IList<Ranorex.ThTag> myList = table.FindDescendants<Ranorex.ThTag>();
foreach(Ranorex.ThTag tag in myList )
{
tag.InnerText.Click();
Delay.Milliseconds(5000);
tag.InnerText.Click();
}
Re: Loop/Click Inner Text
Posted: Mon Sep 17, 2012 11:40 pm
by Ciege
Whats your question here? Does the first code snippet work and the second one not work?
Re: Loop/Click Inner Text
Posted: Tue Sep 18, 2012 4:43 am
by regex
I want to click on the inner text of all the column headings. The first code doesn't click on the inner text. It clicks on the area which doesn't invoke any behavior.
I want to know if you had a solution.
Re: Loop/Click Inner Text
Posted: Tue Sep 18, 2012 6:21 am
by artur_gadomski
Try Click(Location.Center)
Re: Loop/Click Inner Text
Posted: Tue Sep 18, 2012 5:12 pm
by regex
Thanks for that snippet.
click.(Location.CenterLeft) worked.
Except the cursor moves to the top left of the screen after succesfully clicking a header. It seems like a bug.
Code: Select all
public void verifyAsc()
{
var grid = Table;
IList<Ranorex.ThTag> myList = grid.FindDescendants<Ranorex.ThTag>();
foreach(Ranorex.ThTag tag in myList )
{
tag.Click(Location.CenterLeft);
Delay.Milliseconds(1000);
}
Re: Loop/Click Inner Text
Posted: Tue Sep 18, 2012 5:34 pm
by Ciege
When the cursor moves to the top left of the page it usually means that Ranorex cannot find the object you are trying to click on anymore (i.e. it is not a valid object anymore).
Could it be that after you click the first header, the page refreshes thus invalidating the elements you have searched for and added to your list of tags?
Re: Loop/Click Inner Text
Posted: Tue Sep 18, 2012 6:00 pm
by regex
That is exactly what is happening. Thank you for explaining that so well Ciege.
The page refreshes with a small wait symbol that temporarily greys the page for a few milliseconds.
So create a new list when the item has been clicked? Or should I invalidate the list altogether and focus on clicking the individual items? Thanks.
Re: Loop/Click Inner Text
Posted: Tue Sep 18, 2012 6:23 pm
by Ciege
So create a new list when the item has been clicked? Or should I invalidate the list altogether and focus on clicking the individual items?
That depends on what you are trying to accomplish and what you know before hand...
Do you already know the names of the headers you want to click? If so, you can create a list of headers then pass each header name to a method that searches for and clicks that header...
For example some quick and dirty pseudo code to follow:
Code: Select all
//First create a list of header names you would want to click
//Then loop through that list and click them
foreach header in MyListOfHeaders
{
clickTag(DOMElement, header)
}
//New method to search for and click the tag by name...
public static int clickTag(Ranorex.WebDocument MyWebDocument, string header)
{
IList<Ranorex.ThTag> myList = grid.FindDescendants<Ranorex.ThTag>();
foreach(Ranorex.ThTag tag in myList )
{
if tag.innertext.contains header
tag.Click(Location.CenterLeft);
//wait for page to refresh
while (MyWebDocument.State.ToUpper() != "COMPLETE")
{ Delay.Milliseconds(1000);}
}
}
Re: Loop/Click Inner Text
Posted: Wed Sep 19, 2012 3:34 pm
by regex
This isn't working.
Code: Select all
public void clickTag()
{
var grid = path;
IList<Ranorex.ThTag> myList = grid.FindDescendants<Ranorex.ThTag>();
foreach(Ranorex.ThTag tag in myList )
clickTag(Ranorex.ThTag, header);
}
public static void Asc4(string header)
{
Ranorex.WebDocument workList = path;
Ranorex.ThTag thTag = null;
thTag.ToString();
var grid = path;
IList<Ranorex.ThTag> myList = grid.FindDescendants<Ranorex.ThTag>();
foreach(Ranorex.ThTag tag in myList )
{
tag.Click(Location.CenterLeft);
while (workList.State.ToUpper() != "COMPLETE")
{ Delay.Milliseconds(4000);}
}
}
Re: Loop/Click Inner Text
Posted: Wed Sep 19, 2012 4:16 pm
by Ciege
OK, why not?
What happens? Are you following the logic I lined out above?
1) get a list of header NAMES not a list of header tags.
2) pass each name, one at a time to the new clickTag method.
3) in the clickTag method search the form for the header that contains or equals the name you want to click
4) click it
5) wait for the webpage to refresh
6) rinse & repeat...
Re: Loop/Click Inner Text
Posted: Mon Sep 24, 2012 1:09 pm
by regex
Since I'm having a bit of trouble with this, I decided to try just manually adding click's for each header column. But I tried using finding items in a list.
Code: Select all
Ranorex.TdTag obj = -0;
var grid =Table;
// get all columns in specified row and store them in a list
IList<Ranorex.TdTag> myCols = grid.FindDescendants<Ranorex.TdTag>();
foreach(Ranorex.TdTag tag in myCols)
{
//tag.Element.get
Report.Log(ReportLevel.Info,"Row Count: ", myCols.Count.ToString());
obj = myCols.Single( i => i.ID == 4 );
}
I get this error:
'System.Collections.Generic.IList<Ranorex.TdTag>' does not contain a definition for 'Find' and no extension method 'Find' accepting a first argument of type 'System.Collections.Generic.IList<Ranorex.TdTag>' could be found (are you missing a using directive or an assembly reference?)
I have all linq references added. I also tried another one without using linq. All I want to do is find the items within the list and this is giving me an error.
From this:
http://www.dotnetperls.com/list-find
Re: Loop/Click Inner Text
Posted: Tue Sep 25, 2012 7:08 am
by artur_gadomski
When Linq fails just use foreach.
Ranorex.TdTag obj = -0;
var grid =Table;
// get all columns in specified row and store them in a list
IList<Ranorex.TdTag> myCols = grid.FindDescendants<Ranorex.TdTag>();
foreach(Ranorex.TdTag tag in myCols)
{
//tag.Element.get
Report.Log(ReportLevel.Info,"Row Count: ", myCols.Count.ToString());
if (tag.ID == 4) {
obj = tag;
break;
}
}
Of course this is just your code transformed it's possible your code doesn't work.