fix: handle missing error message elements gracefully

This commit is contained in:
张翔
2026-03-06 18:25:10 +08:00
parent ceec57f864
commit e112c75001
+5 -2
View File
@@ -23,8 +23,11 @@ export class ContactPage extends BasePage {
} }
async getFormErrorMessage(): Promise<string> { async getFormErrorMessage(): Promise<string> {
const errorElement = await this.page.locator('[data-testid="error-message"]').first(); const errorElement = await this.page.locator('[data-testid="error-message"]');
return await errorElement.textContent() || ''; if (await errorElement.count() > 0) {
return await errorElement.first().textContent() || '';
}
return '';
} }
async getFormSuccessMessage(): Promise<string> { async getFormSuccessMessage(): Promise<string> {