# -*- coding: utf-8 -*- """验证「面板点选」填日期区间:点输入框 → 面板找 td[title] → 点日期格子。""" import json import os import sys import time try: sys.stdout.reconfigure(encoding='utf-8', errors='replace') except Exception: pass REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.join(REPO, 'plugins', 'XQ0001-0100')) sys.path.insert(0, os.path.join(REPO, 'desktop', 'electron-shell', 'python')) from DrissionPage import ChromiumPage page = ChromiumPage('127.0.0.1:9333') def vals(): return page.run_js( "var a=[].slice.call(document.querySelectorAll('input.ant-calendar-picker-input'))" ".filter(function(e){return e.offsetWidth>0;});" "return JSON.stringify(a.map(function(e){return e.value;}));") def heads(): return page.run_js(""" var p = document.querySelector('.ant-calendar-picker-container'); if (!p || !p.offsetWidth) return ''; var l = p.querySelector('.ant-calendar-range-left .ant-calendar-month-select'); var r = p.querySelector('.ant-calendar-range-right .ant-calendar-month-select'); var ly = p.querySelector('.ant-calendar-range-left .ant-calendar-year-select'); var ry = p.querySelector('.ant-calendar-range-right .ant-calendar-year-select'); return JSON.stringify([ly&&ly.innerText, l&&l.innerText, ry&&ry.innerText, r&&r.innerText]); """) def mark(title): return page.run_js(""" var t = arguments[0]; var p = document.querySelector('.ant-calendar-picker-container'); if (!p) return 'no-panel'; var tds = [].slice.call(p.querySelectorAll('td[title]')); var hit = tds.filter(function(e){return (e.getAttribute('title')||'') === t;})[0]; if (!hit) return 'not-found'; hit.id = '__pick_day__'; return 'ok'; """, title) def click_next(): return page.run_js(""" var p = document.querySelector('.ant-calendar-picker-container'); if (!p) return false; var b = p.querySelector('.ant-calendar-range-right .ant-calendar-next-month-btn'); if (!b) b = p.querySelector('.ant-calendar-next-month-btn'); if (b) { b.click(); return true; } return false; """) def click_prev(): return page.run_js(""" var p = document.querySelector('.ant-calendar-picker-container'); if (!p) return false; var b = p.querySelector('.ant-calendar-range-left .ant-calendar-prev-month-btn'); if (!b) b = p.querySelector('.ant-calendar-prev-month-btn'); if (b) { b.click(); return true; } return false; """) def pick(title): st = mark(title) print(' 标记', title, '->', st, flush=True) if st != 'ok': return False el = page.ele('#__pick_day__', timeout=3) if not el: print(' 取不到元素', flush=True) return False el.click() time.sleep(0.8) page.run_js("var e=document.getElementById('__pick_day__'); if(e) e.id='';") return True print('当前值:', vals(), flush=True) boxes = [el for el in page.eles('css:input.ant-calendar-picker-input') if el.states.is_displayed] print('日期框数量:', len(boxes), flush=True) boxes[0].click() time.sleep(1.2) print('面板头:', heads(), flush=True) for title in ('2026年11月3日', '2026年11月3日'): hit = mark(title) tries = 0 while hit == 'not-found' and tries < 24: click_next() time.sleep(0.4) tries += 1 hit = mark(title) if hit == 'not-found': # 往回翻 for _ in range(24): click_prev() time.sleep(0.4) if mark(title) == 'ok': hit = 'ok' break print('翻月', tries, '次后:', title, hit, '面板头:', heads(), flush=True) if hit != 'ok': print(' 找不到日期格子,放弃', flush=True) break el = page.ele('#__pick_day__', timeout=3) el.click() time.sleep(1) page.run_js("var e=document.getElementById('__pick_day__'); if(e) e.id='';") print(' 点击后值:', vals(), flush=True) print('最终值:', vals(), flush=True)