Powered By Blogger

Search Here!

Tuesday, April 24, 2012

Selenium RC: Find Row Number of Element

This C# method gives you the table row no.of the element. You need to pass the cloumn no. in which you want to make search, ReferenceText the text you want to find out and table locator, after then you could perform any action that row no.


public static int GetRowWithCellText(string columnnum, string ReferenceText, string TableLocator,int startFromRowNum=0)
        {
            ISelenium Selenium = GetSeleniumInstance();
            for (int i = startFromRowNum; ; i++)
            {
                try
                {
                    string elementPresent = Selenium.GetTable(TableLocator + "." + i.ToString() + "." + columnnum).Trim();
                    if (elementPresent.Contains(ReferenceText))
                    {
                        return i;
                    }
                }
                catch (Exception)
                {
                    break;
                }
            }
            return -1;
        }

No comments:

Post a Comment