Maya
Maya

Reputation: 7213

Invalid token 'return' in class, struct, or interface member declaration

return found;

is giving:

Invalid token 'return' in class, struct, or interface member declaration

Code:

public bool IsTextPresent(ISelenium Selenium, string searchText)
    {

        int count = (int)Selenium.GetXpathCount("//*[@id='resultTable']/table");
        string text;

        bool found;

        for (int i = 1; i <= count; i++) 
        {
            StringBuilder container = new StringBuilder();

            for (int j = 4; j <= 8; j += 2)
            {

                if (Selenium.IsElementPresent("xpath=/html/body/form/div[2]/table[" + (i) + "]/tr[" + (j) + "]/td[4]"))
                {
                    text = Selenium.GetText("xpath=/html/body/form/div[2]/table[" + (i) + "]/tr[" + (j) + "]/td[4]");


                    container.Append(text + Environment.NewLine);
                }

                string fullText = container.ToString();
                    if (!fullText.Contains(searchText))
                    {
                        found = false;
                    }
                    else
                    {
                        found =  true;
                    }
                }
            }
        }
        return found;            
    }

Upvotes: 2

Views: 9237

Answers (5)

James Michael Hare
James Michael Hare

Reputation: 38397

You have too many closing curly braces... Your indented if at end is confusing your number of closing }s:

        string fullText = container.ToString();
            if (!fullText.Contains(searchText))
            {
                found = false;
            }
            else
            {
                found =  true;
            }
        } // <<<< The indention of the if probably threw you off here...

Upvotes: 4

devdigital
devdigital

Reputation: 34349

You have placed return found; after the methods closing brace. Align the code properly to see. Use Ctrl-K, Ctrl-D to format the code in Visual Studio.

Upvotes: 2

Henk Holterman
Henk Holterman

Reputation: 273274

This part contains one too many }, terminating the method:

     string fullText = container.ToString();
                if (!fullText.Contains(searchText))
                {
                    found = false;
                }
                else
                {
                    found =  true;
                }
            }  // remove this one

Upvotes: 2

Joe
Joe

Reputation: 42627

Really? Count your open and closing braces.

Upvotes: 1

Ed Bayiates
Ed Bayiates

Reputation: 11220

Your braces mismatch, so the return is outside the function definition.

Upvotes: 2

Related Questions