diff --git a/x-pack/test/functional/page_objects/security_page.js b/x-pack/test/functional/page_objects/security_page.js
index 4803596b973bc..4b097b916573d 100644
--- a/x-pack/test/functional/page_objects/security_page.js
+++ b/x-pack/test/functional/page_objects/security_page.js
@@ -110,12 +110,7 @@ export function SecurityPageProvider({ getService, getPageObjects }) {
       }
 
       await userMenu.clickLogoutButton();
-
-      await retry.waitForWithTimeout(
-        'login form',
-        config.get('timeouts.waitFor') * 5,
-        async () => await find.existsByDisplayedByCssSelector('.login-form')
-      );
+      await this.waitForLoginForm();
     }
 
     async forceLogout() {
@@ -129,11 +124,17 @@ export function SecurityPageProvider({ getService, getPageObjects }) {
       const url = PageObjects.common.getHostPort() + '/logout';
       await browser.get(url);
       log.debug('Waiting on the login form to appear');
-      await retry.waitForWithTimeout(
-        'login form',
-        config.get('timeouts.waitFor') * 5,
-        async () => await find.existsByDisplayedByCssSelector('.login-form')
-      );
+      await this.waitForLoginForm();
+    }
+
+    async waitForLoginForm() {
+      await retry.waitForWithTimeout('login form', config.get('timeouts.waitFor') * 5, async () => {
+        const alert = await browser.getAlert();
+        if (alert && alert.accept) {
+          await alert.accept();
+        }
+        return await find.existsByDisplayedByCssSelector('.login-form');
+      });
     }
 
     async clickRolesSection() {