定位器已隐藏

问题描述 投票:0回答:1

这是我在 Playwright 中的代码:

await this.uploadAssetInputLink().waitFor({ timeout: 60000 });
const fileChooserPromise = this.page.waitForEvent("filechooser");
await this.uploadAssetInputLink().click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(imgPath);
await this.elementTile().waitFor();
expect(this.elementTile()).toHaveCount(1);

我收到以下错误:

  TimeoutError: locator.waitFor: Timeout 60000ms exceeded.
    Call log:
      - waiting for getByTestId('graphics-file-input').first() to be visible
      -   locator resolved to hidden <input type="file" id="graphics-file-input" data-test-id="graphics-file-input" accept=".jpg,.jpeg,.png,image/jpeg,image/png,image/svg+xml"/>

我正在尝试上传文件,但选择器被隐藏。在这种情况下我能做什么?用于上传元素的 HTML 元素已显示 - 隐藏。

playwright
1个回答
0
投票

您无需单击该元素并等待文件选择器。

await fileChooser.setFiles(imgPath);
应该是您需要对该元素执行的所有操作。

© www.soinside.com 2019 - 2024. All rights reserved.