|
|
|
@@ -515,40 +515,40 @@ class SigaDespesasAutomation:
|
|
|
|
await human_delay(400, 800)
|
|
|
|
await human_delay(400, 800)
|
|
|
|
await dp.wait_for(state="visible", timeout=4000)
|
|
|
|
await dp.wait_for(state="visible", timeout=4000)
|
|
|
|
|
|
|
|
|
|
|
|
# Ajusta o mês no calendário clicando na seta esquerda (th.prev) até exibir o mês alvo (ex: JULHO)
|
|
|
|
# # Ajusta o mês no calendário clicando na seta esquerda (th.prev) até exibir o mês alvo (ex: JULHO)
|
|
|
|
header_month = page.locator(".datepicker-days th.switch, .datepicker th.switch").first
|
|
|
|
# header_month = page.locator(".datepicker-days th.switch, .datepicker th.switch").first
|
|
|
|
target_month_name = portuguese_months.get(target_date.month, "JULHO")
|
|
|
|
# target_month_name = portuguese_months.get(target_date.month, "JULHO")
|
|
|
|
|
|
|
|
|
|
|
|
for attempt in range(6):
|
|
|
|
# for attempt in range(6):
|
|
|
|
if not await header_month.is_visible():
|
|
|
|
# if not await header_month.is_visible():
|
|
|
|
break
|
|
|
|
# break
|
|
|
|
|
|
|
|
|
|
|
|
current_header = normalize_text(await header_month.inner_text())
|
|
|
|
# current_header = normalize_text(await header_month.inner_text())
|
|
|
|
if target_month_name in current_header:
|
|
|
|
# if target_month_name in current_header:
|
|
|
|
logger.info(f"📅 Datepicker exibindo o mês correto: '{current_header}'")
|
|
|
|
# logger.info(f"📅 Datepicker exibindo o mês correto: '{current_header}'")
|
|
|
|
break
|
|
|
|
# break
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"⏪ Datepicker exibe '{current_header}' (Esperado: '{target_month_name}'). Clicando na seta esquerda (th.prev) para voltar 1 mês...")
|
|
|
|
# logger.info(f"⏪ Datepicker exibe '{current_header}' (Esperado: '{target_month_name}'). Clicando na seta esquerda (th.prev) para voltar 1 mês...")
|
|
|
|
prev_arrow = page.locator(".datepicker-days th.prev, .datepicker th.prev").first
|
|
|
|
# prev_arrow = page.locator(".datepicker-days th.prev, .datepicker th.prev").first
|
|
|
|
await mouse.click_element(prev_arrow)
|
|
|
|
# await mouse.click_element(prev_arrow)
|
|
|
|
await human_delay(500, 900)
|
|
|
|
# await human_delay(500, 900)
|
|
|
|
|
|
|
|
|
|
|
|
# Clica no dia exato das células do mês corrente (ignora .old e .new)
|
|
|
|
# # Clica no dia exato das células do mês corrente (ignora .old e .new)
|
|
|
|
cells = page.locator(".datepicker-days td.day:not(.old):not(.new)")
|
|
|
|
# cells = page.locator(".datepicker-days td.day:not(.old):not(.new)")
|
|
|
|
count = await cells.count()
|
|
|
|
# count = await cells.count()
|
|
|
|
day_str = str(target_date.day)
|
|
|
|
# day_str = str(target_date.day)
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(count):
|
|
|
|
# for i in range(count):
|
|
|
|
cell = cells.nth(i)
|
|
|
|
# cell = cells.nth(i)
|
|
|
|
if (await cell.inner_text()).strip() == day_str:
|
|
|
|
# if (await cell.inner_text()).strip() == day_str:
|
|
|
|
try:
|
|
|
|
# try:
|
|
|
|
await mouse.click_element(cell)
|
|
|
|
# await mouse.click_element(cell)
|
|
|
|
logger.info(f"📅 Data selecionada no datepicker: {target_date.strftime('%d/%m/%Y')}")
|
|
|
|
# logger.info(f"📅 Data selecionada no datepicker: {target_date.strftime('%d/%m/%Y')}")
|
|
|
|
await human_delay(400, 700)
|
|
|
|
# await human_delay(400, 700)
|
|
|
|
return
|
|
|
|
# return
|
|
|
|
except Exception as cell_err:
|
|
|
|
# except Exception as cell_err:
|
|
|
|
logger.warning(f"⚠️ Clique direto no dia falhou ({cell_err}). Acionando digitação direta...")
|
|
|
|
# logger.warning(f"⚠️ Clique direto no dia falhou ({cell_err}). Acionando digitação direta...")
|
|
|
|
break
|
|
|
|
# break
|
|
|
|
|
|
|
|
|
|
|
|
# Fallback: preenchimento direto da data se o clique no calendário não fechar
|
|
|
|
# Fallback: preenchimento direto da data se o clique no calendário não fechar
|
|
|
|
logger.warning(f"⚠️ Preenchendo a data {target_date.strftime('%d/%m/%Y')} diretamente via teclado...")
|
|
|
|
logger.warning(f"⚠️ Preenchendo a data {target_date.strftime('%d/%m/%Y')} diretamente via teclado...")
|
|
|
|
@@ -591,7 +591,7 @@ class SigaDespesasAutomation:
|
|
|
|
|
|
|
|
|
|
|
|
# 2. Clica no campo de busca e preenche com fill + press ("Enter") se for AJAX ou seleciona da li
|
|
|
|
# 2. Clica no campo de busca e preenche com fill + press ("Enter") se for AJAX ou seleciona da li
|
|
|
|
clean_search = normalize_text(search_text)
|
|
|
|
clean_search = normalize_text(search_text)
|
|
|
|
#await mouse.click_element(search_input)
|
|
|
|
await mouse.click_element(search_input)
|
|
|
|
await search_input.fill(clean_search)
|
|
|
|
await search_input.fill(clean_search)
|
|
|
|
await search_input.dispatch_event("input")
|
|
|
|
await search_input.dispatch_event("input")
|
|
|
|
await human_delay(300, 600)
|
|
|
|
await human_delay(300, 600)
|
|
|
|
@@ -603,6 +603,8 @@ class SigaDespesasAutomation:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await human_delay(400, 800)
|
|
|
|
await human_delay(400, 800)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Jhony todo: Adicione a verificação se realmente o item clean_search foi encontrado com caracteres permissivos.
|
|
|
|
|
|
|
|
|
|
|
|
# 3. Localiza e clica no item da lista (#select2-drop .select2-results li)
|
|
|
|
# 3. Localiza e clica no item da lista (#select2-drop .select2-results li)
|
|
|
|
results = page.locator("#select2-drop .select2-results li.select2-result-selectable")
|
|
|
|
results = page.locator("#select2-drop .select2-results li.select2-result-selectable")
|
|
|
|
count = await results.count()
|
|
|
|
count = await results.count()
|
|
|
|
@@ -616,16 +618,17 @@ class SigaDespesasAutomation:
|
|
|
|
await mouse.click_element(item)
|
|
|
|
await mouse.click_element(item)
|
|
|
|
logger.info(f"✅ Opção Select2 selecionada com sucesso: '{item_text.strip()}'")
|
|
|
|
logger.info(f"✅ Opção Select2 selecionada com sucesso: '{item_text.strip()}'")
|
|
|
|
await human_delay(400, 800)
|
|
|
|
await human_delay(400, 800)
|
|
|
|
|
|
|
|
await page.keyboard.press("Enter")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Fallback: se houver opção destacada ou primeira opção clicável
|
|
|
|
# # Fallback: se houver opção destacada ou primeira opção clicável
|
|
|
|
logger.warning(f"⚠️ Seleção exata por texto não casou ('{target_norm}'), clicando na primeira opção visível...")
|
|
|
|
# logger.warning(f"⚠️ Seleção exata por texto não casou ('{target_norm}'), clicando na primeira opção visível...")
|
|
|
|
first_opt = results.first
|
|
|
|
# first_opt = results.first
|
|
|
|
if await first_opt.is_visible():
|
|
|
|
# if await first_opt.is_visible():
|
|
|
|
await mouse.click_element(first_opt)
|
|
|
|
# await mouse.click_element(first_opt)
|
|
|
|
else:
|
|
|
|
# else:
|
|
|
|
await page.keyboard.press("Enter")
|
|
|
|
# await page.keyboard.press("Enter")
|
|
|
|
await human_delay(500, 900)
|
|
|
|
# await human_delay(500, 900)
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# 3. PREENCHIMENTO COMPLETO DO FORMULÁRIO DE DESPESA
|
|
|
|
# 3. PREENCHIMENTO COMPLETO DO FORMULÁRIO DE DESPESA
|
|
|
|
|