I need to click on a "account" button from a table of buttons. If this "account" button is not present, then I will need to click a different "UseAnotherAccount" button.
How I do it at the moment is:
- Set a flag
account_foundto be false by default - use a
foreachloop to search through the whole_listof buttons - If the expected account button is found, click it, set
account_foundflag to be true and break away from thisforeachloop - an additional
ifblock is used to to click onUseAnotherAccountbutton ifaccount_foundflag is not set.
My code is shown below:
bool account_found = false;
foreach (DivTag element in _list) {
String account_name = element.GetInnerHtml();
if (account_name.Equals(_account_name)) {
element.Click();
account_found = true;
break;
}
}
if (!account_found) {
_my_repo.SignInToYourAccount.UseAnotherAccount.Click();
}
I have this feeling my way is not the most elegant way to achieve this. Any suggestions?