控制不能从一个case标签通过下跌 [英] Control cannot fall through from one case label

查看:135
本文介绍了控制不能从一个case标签通过下跌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写这将在搜索领域依赖于任何搜索文本框中键入搜索词的开关语句是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#允许

通过添加在每种情况下的最后陈述时,程序退出它的完成后,为检索类别

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 under case "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 of searchType.

这篇关于控制不能从一个case标签通过下跌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆