diff --git a/playwright_automation.py b/playwright_automation.py index df4375d..a547eb0 100755 --- a/playwright_automation.py +++ b/playwright_automation.py @@ -1361,31 +1361,43 @@ class PlaywrightAutomation: # 先保存到临时文件 temp_filepath = filepath + '.tmp' - # 尝试展开iframe以显示全部内容 + # 展开所有可滚动容器,使内容完全显示 try: self.main_page.evaluate("""() => { - const iframe = document.querySelector('iframe[name="mainframe"]'); - if (iframe) { - try { - const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; - const contentHeight = Math.max( - iframeDoc.body.scrollHeight, - iframeDoc.documentElement.scrollHeight, - 2000 - ); - iframe.style.height = contentHeight + 'px'; - iframe.style.minHeight = contentHeight + 'px'; - iframe.style.maxHeight = 'none'; - // 调整父容器 - let parent = iframe.parentElement; - while (parent && parent !== document.body) { - parent.style.height = 'auto'; - parent.style.maxHeight = 'none'; - parent.style.overflow = 'visible'; - parent = parent.parentElement; - } - } catch(e) {} - } + // 移除body和html的高度限制 + document.documentElement.style.height = 'auto'; + document.documentElement.style.overflow = 'visible'; + document.body.style.height = 'auto'; + document.body.style.overflow = 'visible'; + + // 查找所有可能的滚动容器并展开 + const expandScrollable = (el) => { + if (!el || el === document.documentElement) return; + const style = window.getComputedStyle(el); + if (style.overflow === 'auto' || style.overflow === 'scroll' || + style.overflowY === 'auto' || style.overflowY === 'scroll') { + el.style.height = 'auto'; + el.style.maxHeight = 'none'; + el.style.overflow = 'visible'; + } + if (el.parentElement) expandScrollable(el.parentElement); + }; + + // 从表格开始向上展开 + const table = document.querySelector('table.ltable, .ltable, table'); + if (table) expandScrollable(table.parentElement); + + // 展开所有带overflow的元素 + document.querySelectorAll('*').forEach(el => { + const style = window.getComputedStyle(el); + if ((style.overflow === 'auto' || style.overflow === 'scroll' || + style.overflowY === 'auto' || style.overflowY === 'scroll') && + el.scrollHeight > el.clientHeight) { + el.style.height = el.scrollHeight + 'px'; + el.style.maxHeight = 'none'; + el.style.overflow = 'visible'; + } + }); }""") time.sleep(0.5) except Exception: