0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Playwright でページに複数個の要素が存在することを検証する

Posted at

HTML

HTMLにはこんな風にテキストが10個あるとする

<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>
<div>FOO TEXT</div>

Playwright

専用の書き方があるわけではなく、ループで回せば良いようだ

画面に FOO TEXT というテキストが10個あることを検証する例

for (let i = 0; i < 10; i++) {
  await expect(page.getByText('FOO TEXT').nth(i)).toBeVisible()
}



nth

なお Playwright の nth では指定順番の要素を得られるようだが、 0始まりのカウントのようだ

  • nth(0) が1番目の要素
  • nth(1) が1番目の要素

Returns locator to the n-th matching element. It's zero based, nth(0) selects the first element.

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

プロフィール・経歴

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?