.Contains("text") question

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

.Contains("text") question

Post by regex » Tue Oct 02, 2012 7:53 pm

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

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

Re: .Contains("text") question

Post by Ciege » Tue Oct 02, 2012 10:06 pm

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");
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...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: .Contains("text") question

Post by Support Team » Wed Oct 03, 2012 12:12 pm

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
.
Image

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

Re: .Contains("text") question

Post by regex » Wed Oct 03, 2012 2:43 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: .Contains("text") question

Post by Support Team » Thu Oct 04, 2012 3:00 pm

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
.
Image