Page 1 of 1

Find a value in a Table.

Posted: Thu Jul 12, 2012 9:56 pm
by IanF
We have a tables with embebed buttons and I need to be able to match a value in a table and select its button.

The find value part.

Code: Select all

 /// <summary>
        /// Searches a table for a particular text value, and then finds a corresponding UI element in that row.
        /// </summary>
        /// <param name="table">Table to search.</param>
        /// <param name="rowText">Text to find in a row. e.g. "Bob Smith"</param>
        /// <param name="rowTextExpression">XPath Expression used to find the text. e.g. "./span"</param>
        /// <param name="adapterExpression">Expression used to return the adapter, once the text has been found. e.g. "../div/input[@type='text']"</param>
        /// <returns></returns>
        public static T SearchTable<T>(Adapter table, string rowText, string rowTextExpression, string adapterExpression) where T : Adapter
        {		  
			// Find Licence and push select   
			foreach (TrTag row in table.Find("./tbody/tr"))
			{    
			    foreach (TdTag cell in row.Find("./td"))   
			    {   
			    	WebElement span = cell.FindSingle(rowTextExpression);
			    	
			        if (span.InnerText == rowText)
			        {
			        	T element = row.FindSingle<T>(adapterExpression);
			        	return element;
			        }
			        break;
			    }   		  
			}
			return null;
        }
In use clicking the button.

Code: Select all

public void FindButton(string argument1)
        {		  
        	var button = UserCodeModule1.SearchTable<InputTag>(repo.Select_Licensee1.LicenceeTable, argument1, "./span", "./td/input");
        	if (button != null)
        	{
        		button.Click();
        		Report.Success("Licencee Found", argument1);
        	}        	
        }
Hope you find it helpfull.

Re: Find a value in a Table.

Posted: Mon Jul 16, 2012 3:01 pm
by omayer
Thank you Ian to share the code, this is very helpful.

Re: Find a value in a Table.

Posted: Mon Jul 16, 2012 9:52 pm
by IanF
It is still a work in progress. We made changes to this to allowing for paging for results. When it is done I will post it.