RobotFramework Browser库找不到元素(本地测试和服务器不一致)

# 问题背景

使用Browser库写的UI自动化用例,在本地测试是可以正常跑过的,提交代码后服务器跑不通过,报错如下,并且我打开有头浏览器可以看到元素是正常加载完成了的

TimeoutError: locator.waitFor: Timeout 30000ms exceeded.

Call log:

  • waiting for locator('iframename="pdiv_page-mainIframe"').contentFrame().locator('iframe').contentFrame().locator('role=columnheadername="开始时间(秒)"') to be visible

元素本身如下

<th _ngcontent-ng-c691599427="" title="开始时间(秒)" class="ng-star-inserted"><div class="plx-table-x-th-content"><span _ngcontent-ng-c691599427="">开始时间(秒)</span><!----><plx-table-x-resize _ngcontent-ng-c691599427="" class="ng-star-inserted"><span class="table-x-resize-line"></span></plx-table-x-resize><!----></div><!----><!----><!----><!----></th>

原代码如下:

对应Python: expect(page.locator("iframename=\\"pdiv_page-mainIframe\\"").content_frame.locator("iframe").content_frame.get_by_role("columnheader", name="开始时间(秒)")).to_be_visible()

等待元素出现 ${NESTED_IFRAME} >>> role=columnheadername="开始时间(秒)"

# 问题原因 (deepseek给的)

核心矛盾 :你使用的是 role=columnheader[name="开始时间(秒)"] 定位器,但浏览器在无头模式下为该 <th> 计算出的可访问性名称可能不是 " 开始时间(秒)" ,因为文本节点内容是 " 开始时间(秒) "(前后有空格),而可访问性名称通常会被规范化(trim)。此外,role=columnheader 依赖于可访问性树的构建,无头模式下的计算时序有延迟,导致超时。

# 解决方法

修改元素定位方式,建议表格有表头的不要使用role=columnheader这种定位方式

Wait For Elements State ${NESTED_IFRAME} >>> th:has-text("开始时间(秒)") visible timeout=60s

相关推荐
Sarapines Programmer3 小时前
【Wireshark】安装与使用指南
网络·测试工具·wireshark
念越12 小时前
接口自动化测试从入门到实战:接口用例设计、Requests、Pytest、YAML、JSON Schema 与 Allure 报告
python·测试工具·自动化·json·pytest
ysu_03142 天前
Postman接口调试实战指南-从HTTP请求到环境变量-Collection与自动化测试
网络·网络协议·测试工具·http·api·postman·可用性测试
ZhangJun953 天前
从零写一个类鲁大师的硬件检测小工具,软件附上,可直接使用
windows·测试工具·电脑·笔记本电脑·硬件架构
skywalk81634 天前
这是什么意思?浏览器实机渲染,本机无 jsdom / headless
playwright·headless·jsdom
深蓝电商API5 天前
Puppeteer vs Playwright:多维度压测后的选型建议
爬虫·puppeteer·playwright
蒸鱼Yuzheng5 天前
自动化 Socket 协议设计:消息序列、心跳、幂等重试与背压
自动化测试·python·websocket·socket·分布式系统
测试者家园5 天前
不写测试用例也能做自动化测试?
自动化测试·软件测试·人工智能·测试用例·智能化测试
测试员周周5 天前
【jev应用到测试】94 条 UI 报错交给 Jev,三档判对 85.1%,开单闸门定在 0.6
人工智能·python·测试工具·单元测试·测试用例
xfilm埃利测量5 天前
从方阻到电阻率:四探针法如何把薄膜“测明白“
功能测试·测试工具·四探针·薄膜电阻测量