控制不能从一个case标签通过下跌 [英] Control cannot fall through from one case label
问题描述
我想写这将在搜索领域依赖于任何搜索文本框中键入搜索词的开关语句是present。我有以下的code。但是,我得到一个错误Control无法通过从一个case标签落。请让我知道如何解决这一问题。在此先感谢!
开关(搜索类型)
{
案SearchBooks:
Selenium.Type(// * [@ ID ='SearchBooks_TextInput'],SEARCHTEXT);
Selenium.Click(// * [@ id中='SearchBooks_SearchBtn']);案SearchAuthors:
Selenium.Type(// * [@ ID ='SearchAuthors_TextInput'],SEARCHTEXT);
Selenium.Click(// * [@ id中='SearchAuthors_SearchBtn']);
}
控制不能从一个case标签告吹('案SearchBooks:')到另一个
控制不能从一个case标签告吹('案SearchAuthors:')到另一个
块引用>解决方案您错过了一些突破有:
开关(搜索类型)
{
案SearchBooks:
Selenium.Type(// * [@ ID ='SearchBooks_TextInput'],SEARCHTEXT);
Selenium.Click(// * [@ id中='SearchBooks_SearchBtn']);
打破; 案SearchAuthors:
Selenium.Type(// * [@ ID ='SearchAuthors_TextInput'],SEARCHTEXT);
Selenium.Click(// * [@ id中='SearchAuthors_SearchBtn']);
打破;
}如果没有他们,编译器认为你要执行以下
案SearchAuthors的台词:
在情况下,行之后立即SearchBooks :
被执行,这是不是在C#允许通过添加
破
在每种情况下的最后陈述时,程序退出它的完成后,为检索类别取其值每个案件code>。
I am trying to write a switch statement that would type the search term in the search field depending on whichever search textbox is present. I have the following code. But I am getting a "Control cannot fall through from one case label" error. Please let me know how to fix this. Thanks in advance!
switch (searchType) { case "SearchBooks": Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText); Selenium.Click("//*[@id='SearchBooks_SearchBtn']"); case "SearchAuthors": Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText); Selenium.Click("//*[@id='SearchAuthors_SearchBtn']"); }
Control cannot fall through from one case label ('case "SearchBooks":') to another
Control cannot fall through from one case label ('case "SearchAuthors":') to another
解决方案You missed some breaks there:
switch (searchType) { case "SearchBooks": Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText); Selenium.Click("//*[@id='SearchBooks_SearchBtn']"); break; case "SearchAuthors": Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText); Selenium.Click("//*[@id='SearchAuthors_SearchBtn']"); break; }
Without them, the compiler thinks you're trying to execute the lines below
case "SearchAuthors":
immediately after the lines undercase "SearchBooks":
have been executed, which isn't allowed in C#.By adding the
break
statements at the end of each case, the program exits each case after it's done, for whichever value ofsearchType
.这篇关于控制不能从一个case标签通过下跌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!