feat: add persistent browser utility for session management and improve RPA element interaction logging and robustness

This commit is contained in:
2026-05-31 23:59:59 -06:00
parent b366d914a4
commit 43d37f0f0a
2 changed files with 63 additions and 4 deletions

View File

@@ -487,7 +487,7 @@ class SigaAutomation:
async def validate_and_enter_month(self):
page = self.page
now = datetime.now()
now = datetime.now() #- timedelta(days=1)
month_text = f"Mês de Trabalho {now.month:02d}/{now.year}"
month_link = page.get_by_role("link", name=month_text)
@@ -601,6 +601,9 @@ class SigaAutomation:
await human_delay(150, 350)
# Localiza todas as células do mês atual (sem .old e sem .new)
# prev_month = dp.locator(".icon-arrow-left")
# await mouse.click_element(prev_month)
# await human_delay(250, 550)
cells = dp.locator("td.day:not(.old):not(.new)")
count = await cells.count()
@@ -675,7 +678,9 @@ class SigaAutomation:
# Estratégia 1: texto exato
try:
exact = page.locator("#select2-drop").get_by_text(code, exact=True)
logger.info(f" Buscando {code_upper} no catalogo.")
if await exact.count() > 0 and await exact.first.is_visible(timeout=2000):
logger.info(f" ✅ {code_upper} encontrado.")
await mouse.click_element(exact.first)
return True
except Exception:
@@ -711,9 +716,15 @@ class SigaAutomation:
async def _cancel_saida(self):
cancel = self.page.locator(
'button.btn.btn-link.no-border[data-dismiss="modal"]',
has_text="Cancelar",
)
'button.btn.btn-link').get_by_text("Cancelar", exact=True)
mouse = self.mouse
cancel_box = await cancel.bounding_box()
if cancel_box:
await mouse.move_to(
cancel_box["x"] + cancel_box["width"] / 2,
cancel_box["y"] - 20,
)
await human_delay(150, 350)
await self.mouse.click_element(cancel)
await human_delay(1000, 2000)
logger.info("🚫 SAÍDA cancelada.")