Page 1 of 1

.Contains("text") question

Posted: Tue Oct 02, 2012 7:53 pm
by regex
I'm iterating through rows. I need to verify that each row contains specific text. I need to ensure that when this is iterating through rows it verifies that one of the cells contains "created". I tried tag.contains("created") and other derivatives. Any help?

Code: Select all

int counter = 0;
        	 var grid =rgMasterTable;
	         IList<Ranorex.TrTag> myList = grid.FindDescendants<Ranorex.TrTag>();  
	         foreach(Ranorex.TrTag tag in myList )  
         	 {  
	         	if(tag != null)
	         	{
	         	
	         	
	         	myList[1].Click(); 
	         		
	         	tag.MoveTo();
	         	Validate.Exists(tag); 
	         	Report.Info(tag.InnerText);
	         	}
	         	
	         	
	         	
	         	//Ranorex.Mouse.Click();
	         	//tag.Click(Location.CenterLeft); 
	         	if (counter == 51)
	         	{
	         		break;
	         	}
	         	}
	         	 
	         	//NativeWindow();
         		counter++;
         		
         	 }
Also tried this from the GUI. Trying to evaluate this cell contains either Created or Ready.

Code: Select all

 public void Validate_QARequestID()
        {
        	if(repo.IDInfo.Exists())
        	{
        		Validate.Attribute(repo.Info, "InnerText", "Created") || Validate.Attribute(repo.IDInfo, "InnerText", "Ready");
        	}
        	
        }

Re: .Contains("text") question

Posted: Tue Oct 02, 2012 10:06 pm
by Ciege
In your first code snippet I don't see where you are using the .contains... Also, if you are looking for "contians" and your string is "Contains" it won't evaluate as true because of the case difference. You need to either ignore case or force both strings to all upper or all lower.

something like:

Code: Select all

tag.InnerText.ToUpper().Contains("CREATED");

Re: .Contains("text") question

Posted: Wed Oct 03, 2012 12:12 pm
by Support Team
Hi,

The second code will not work since the used method is a void method, it wouldn't return a boolean value.
If you want that the method returns a value you have to use another overload of the Validate.Attribute method like the following one:
public static bool Attribute(
	RepoItemInfo itemInfo,
	string name,
	Object value,
	string message,
	bool exceptionOnFail
)
,for more information please take a look at the following link: Validate.Attribute.

Regards,
Markus
Ranorex Support Team

Re: .Contains("text") question

Posted: Wed Oct 03, 2012 2:43 pm
by regex
Thanks for your help guys. When I try this bit, I get object not set to to an instance of an object error.

myList[1].Click();
myList2[10].Click();
tag.InnerText.Contains("CREATED");

I'm running into a problem with the validation only allowing one word. I want to say attribute contains one of these three Created, Ready, Incomplete.

Re: .Contains("text") question

Posted: Thu Oct 04, 2012 3:00 pm
by Support Team
Hello,

It seems that myList or myList2 is not instantiated. Maybe your grid is not available at this time.
If I understand you correctly, you want to make Validate.Exists(tag) only if the inner text 'tag' contains one of the three strings Created, Ready, Incomplete? If you are able to access the inner text of 'tag' then it also exists and Validate.Exists(tag) is not necessary.
if(tag.InnerText.Contains("Created") || tag.InnerText.Contains("Ready") || tag.InnerText.Contains("Incomplete"))
{
   tag.MoveTo();
   Validate.Exists(tag);
   Report.Info(tag.InnerText);
}
Regards,
Bernhard
Ranorex Support Team