return found;
'迴歸' 所賜:無效令牌類,結構或接口成員聲明
Invalid token 'return' in class, struct, or interface member declaration
代碼:
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;
}
我知道正在處理的問題是大括號,但我會質疑這種方法的命名。如果在每個'xpath =/html/body/form/div [2]/table [i]'部分找到搜索字符串,或者更具體地說,如果在最後一個找到該字符串,那麼您只返回true。 – pstrjds