我的代码中有以下元素
<sp-textfield id="library-name-textfield" data-testid="library-name-textfield" quiet="" placeholder="Name" dir="ltr" type="text" focusable="">
#shadow-root
<input class="input" type="text" aria-describedby="sp-help-text" aria-label="Yourname" placeholder="Your name">
</sp-textfield>
我尝试执行以下操作:
await this.inputBrandLibNameTxtBox().waitFor({ state: "visible", timeout: 20000 });
await this.inputBrandLibNameTxtBox().fill(brandName);
在哪里:
inputBrandLibNameTxtBox = () => this.page.getByTestId("library-name-textfield").locator("input");
我收到错误:
TimeoutError: locator.fill: Timeout 20000ms exceeded.
Call log:
- waiting for getByTestId('library-name-textfield').locator('input')
- locator resolved to <input type="text" class="input" aria-label="Your brand name" placeholder="Your brand name" aria-describedby="sp-help-text-2f4953d1"/>
- fill("new-brand--1733244070919")
- attempting fill action
- waiting for element to be visible, enabled and editable
我该如何修复此问题?
我会尝试使用老旧的 console.log 进行调试,并打印出该元素是否对isVisible()函数返回 true
除此之外,您还可以随时等待某些状态变化,例如 await this.element.waitFor( {state: "visible"} ) 另外,您还可以添加更大的超时时间