Actualizar worker-homeserve.js
This commit is contained in:
@@ -152,7 +152,7 @@ async function loginAndProcess(page, creds, jobData) {
|
||||
const select = document.querySelector('select[name="ESTADO"]');
|
||||
if (!select) return false;
|
||||
for (const opt of select.options) {
|
||||
// Busca el código exacto 307
|
||||
// Busca el código exacto
|
||||
if (opt.value == code || opt.text.toUpperCase().includes(code.toUpperCase())) {
|
||||
select.value = opt.value;
|
||||
return true;
|
||||
@@ -171,7 +171,6 @@ async function loginAndProcess(page, creds, jobData) {
|
||||
const obsFilled = await fillFirstThatExists(page, ['textarea[name="Observaciones"]'], jobData.observation);
|
||||
if (!obsFilled) throw new Error('No encontré el recuadro de Observaciones en la web de HomeServe.');
|
||||
|
||||
// 🔴 NUEVO LOCALIZADOR PARA EL CHECKBOX (Sacado de tu HTML)
|
||||
if (jobData.inform_client) {
|
||||
const informCheck = await findLocatorInFrames(page, 'input[name="INFORMO"]');
|
||||
if (informCheck && !(await informCheck.locator.first().isChecked())) {
|
||||
@@ -179,12 +178,28 @@ async function loginAndProcess(page, creds, jobData) {
|
||||
}
|
||||
}
|
||||
|
||||
// 🔴 NUEVO LOCALIZADOR PARA EL BOTÓN GUARDAR (Sacado de tu HTML)
|
||||
const saveBtn = await clickFirstThatExists(page, ['input[name="BTNCAMBIAESTADO"]']);
|
||||
if (!saveBtn) throw new Error('No encuentro el botón para guardar los cambios en HomeServe.');
|
||||
|
||||
console.log('>>> 4. Guardando cambios en HomeServe...');
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
// 🔴 CLICK SEGURO: Usamos Promise.all para asegurarnos de que el clic desencadena la recarga
|
||||
const saveBtnLocator = page.locator('input[name="BTNCAMBIAESTADO"]');
|
||||
|
||||
if (await saveBtnLocator.count() === 0) {
|
||||
throw new Error('No encuentro el botón para guardar los cambios en HomeServe.');
|
||||
}
|
||||
|
||||
// Esperamos a que la página navegue DESPUÉS de hacer clic
|
||||
await Promise.all([
|
||||
page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: CONFIG.NAV_TIMEOUT }),
|
||||
saveBtnLocator.first().click()
|
||||
]);
|
||||
|
||||
// Verificación extra: Comprobar si hay algún mensaje de error rojo devuelto por HomeServe
|
||||
const errorText = await page.locator('font[color="#FF0000"], .Estilo4').first().textContent().catch(() => null);
|
||||
if (errorText && errorText.trim().length > 0) {
|
||||
throw new Error(`HomeServe devolvió un error al guardar: ${errorText.trim()}`);
|
||||
}
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user