Loop/Click Inner Text

Class library usage, coding and language questions.
regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Loop/Click Inner Text

Post by regex » Mon Sep 17, 2012 8:03 pm

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();
         		
         }

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Loop/Click Inner Text

Post by Ciege » Mon Sep 17, 2012 11:40 pm

Whats your question here? Does the first code snippet work and the second one not work?
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Loop/Click Inner Text

Post by regex » Tue Sep 18, 2012 4:43 am

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.

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Loop/Click Inner Text

Post by artur_gadomski » Tue Sep 18, 2012 6:21 am

Try Click(Location.Center)

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Loop/Click Inner Text

Post by regex » Tue Sep 18, 2012 5:12 pm

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);
         		
         }

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Loop/Click Inner Text

Post by Ciege » Tue Sep 18, 2012 5:34 pm

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?
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Loop/Click Inner Text

Post by regex » Tue Sep 18, 2012 6:00 pm

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.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Loop/Click Inner Text

Post by Ciege » Tue Sep 18, 2012 6:23 pm

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);}
  }
}

If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Loop/Click Inner Text

Post by regex » Wed Sep 19, 2012 3:34 pm

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);}
	       	}
       	
		 
		}

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Loop/Click Inner Text

Post by Ciege » Wed Sep 19, 2012 4:16 pm

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...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Loop/Click Inner Text

Post by regex » Mon Sep 24, 2012 1:09 pm

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

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Loop/Click Inner Text

Post by artur_gadomski » Tue Sep 25, 2012 7:08 am

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.