我们如何从剧作家中具有多个 div 标签的下拉列表中选择随机文本?

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

web element 是否可以从下拉列表中选择带有 div 标签的“随机”文本?因为我试图使用剧作家中下面的代码从下拉列表中选择任何随机国家:

const randomCountry = faker.location.country()
await selectCountry().fill(randomCountry)

有时会打字,但提交帐户后不会保存值。我想它需要使用鼠标指针或箭头键从下拉列表中选择值,但我不知道如何以随机方式执行此操作。

我也尝试了这里的建议:剧作家 - 选择随机选项,但没有运气。任何帮助,将不胜感激。非常感谢。

javascript typescript automation dropdown playwright
1个回答
0
投票

由于您的屏幕截图中没有

select
元素,因此您应该尝试使用简单的
click
从列表中选择所需的选项,如下例所示:

test(`select a movie`, async ({ page }) => {
  const movieName = "The Godfather";
  await page.goto("https://mui.com/material-ui/react-autocomplete/");

  const movieDropDownLocator = page.locator("#combo-box-demo");

  await movieDropDownLocator.click();
  await page.getByRole("option", { name: movieName, exact: true }).click();
  await movieDropDownLocator.blur();

  await expect(movieDropDownLocator).toHaveValue(movieName);
});
© www.soinside.com 2019 - 2024. All rights reserved.