Control cannot fall through from one case label

前端 未结 8 1216
旧巷少年郎
旧巷少年郎 2020-11-27 05:50

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

相关标签:
8条回答
  • 2020-11-27 06:29

    In the end of each switch case just add the break statement to resolve this problem like this-

               switch (manu)
                {
                    case manufacturers.Nokia:
                        _phanefact = new NokiaFactory();
                        break;
    
                    case manufacturers.Samsung:
                        _phanefact = new SamsungFactory();
                        break;
    
                }
    
    0 讨论(0)
  • 2020-11-27 06:31

    You missed break statements.Don't forget to enter break statement even in default case.

    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;
        default :
            Console.WriteLine("Default case handling");
            break;
    
    }
    
    0 讨论(0)
提交回复
热议问题