0
我需要编写一个条件语句来检查L标签是否存在。C#中的嵌套if语句
- 如果L选项卡不存在,它会打印“L不存在”。
- 如果选择L,它将打印“L存在”,并检查是否S,C和K标签存在:
- 若S存在,它会打印出“S是目前”其他“ S是不存在的。
- 如果C是目前它就会打印 “C存在”,否则 “C不存在”,
- ...和同为K.
我写下如下代码,但由于某种原因,代码对我来说看起来不太好,任何想法都可以受到高度赞赏。谢谢!
if (Sel.IsElementPresent(arrObj1[4]))
{
Lib.WriteDebugLogs("Test 1: General", "NORMAL", "L tab present in home page");
Sel.Click(arrObj1[4]);
if (Sel.IsElementPresent(arrObj1[5]))
{
Lib.WriteDebugLogs("Test 1: General", "NORMAL", "S tab present under L tab.");
}
if (Sel.IsElementPresent(arrObj1[6]))
{
Lib.WriteDebugLogs("Test 1: General", "NORMAL", "C tab present under L tab.");
}
if (Sel.IsElementPresent(arrObj1[7]))
{
Lib.WriteDebugLogs("Test 1: General", "NORMAL", "K tab present under L tab.");
}
}
else
{
s = "'L' tab is not displayed in the home page.";
arrTestResults[6] = arrTestResults[7] = s;
Lib.WriteDebugLogs("Test 1: General", "****ERROR****", "Could noT find the L tab");
}
使代码更具可读性的一个非常简单的事情是用一个自我注释标识符(例如'tabK'等变量)替换'arrObj1 [x]' - 可以说这样做不会使用'arrObj1'数组根本... – 2011-06-07 22:00:14