diff --git a/SfeduSchedule/Playwright/MicrosoftLoginHelper.cs b/SfeduSchedule/Playwright/MicrosoftLoginHelper.cs index 2b107b4..31e14d9 100644 --- a/SfeduSchedule/Playwright/MicrosoftLoginHelper.cs +++ b/SfeduSchedule/Playwright/MicrosoftLoginHelper.cs @@ -15,9 +15,16 @@ public static class MicrosoftLoginHelper await page.WaitForURLAsync(new Regex("login\\.(microsoftonline|live)\\.com", RegexOptions.IgnoreCase), new PageWaitForURLOptions { Timeout = 60_000 }); - var useAnotherAccount = page.Locator("div#otherTile, #otherTileText, div[data-test-id='useAnotherAccount']"); - if (await useAnotherAccount.First.IsVisibleAsync(new LocatorIsVisibleOptions { Timeout = 2000 })) - await useAnotherAccount.First.ClickAsync(); + var useAnotherAccount = page.Locator("div#otherTile, #otherTileText, div[data-test-id='useAnotherAccount']").First; + try + { + await Assertions.Expect(useAnotherAccount).ToBeVisibleAsync(new() { Timeout = 2000 }); + await useAnotherAccount.ClickAsync(); + } + catch (PlaywrightException) + { + // Кнопка не появилась — пропускаем + } var emailInput = page.Locator("input[name='loginfmt'], input#i0116"); await emailInput.WaitForAsync(new LocatorWaitForOptions { State = WaitForSelectorState.Visible, Timeout = 30_000 }); @@ -33,15 +40,20 @@ public static class MicrosoftLoginHelper await page.WaitForSelectorAsync("button, input[type='submit'], a", new PageWaitForSelectorOptions { Timeout = 8000 }); - var kmsiYesNoVisible = await page.Locator("#idSIButton9, #idBtn_Back").First.IsVisibleAsync(new LocatorIsVisibleOptions { Timeout = 3000 }); - if (kmsiYesNoVisible) + var locator = page.Locator("#idSIButton9, #idBtn_Back").First; + try { + await Assertions.Expect(locator).ToBeVisibleAsync(new() { Timeout = 3000 }); var noBtn = page.Locator("#idBtn_Back"); if (await noBtn.IsVisibleAsync()) await noBtn.ClickAsync(); else await page.Locator("#idSIButton9").ClickAsync(); } + catch (PlaywrightException) + { + // Кнопки не появились — пропускаем этот шаг + } await page.WaitForURLAsync(url => !Regex.IsMatch(new Uri(url).Host, "login\\.(microsoftonline|live)\\.com", RegexOptions.IgnoreCase), new PageWaitForURLOptions { Timeout = 60_000 }); await page.WaitForLoadStateAsync(LoadState.NetworkIdle);