要素のテキストを取得する

Prev Next

Autify Nexusでは、標準のアサーションを利用することで要素のテキストを取得することができるため、可能な限りその機能を使用することをお勧めします。
標準のテキストアサーションでテキストが取得できない場合は、以下の Playwright コードスニペットを回避策として使用できます。

設定方法

  1. 対象要素のCSSセレクターを取得し、メモしておきます。

  2. シナリオに Playwrightコードステップを挿入し、以下のスニペットをそのステップにコピー&ペーストします。

    // TODO: Please replace the selector with the one for the target element
    const selector = "<TODO: REPLACE SELECTOR>";
    // Get the text content of the element
    // If the element is not found, the test will fail here
    const text = await page.locator(selector).first().textContent();
    
    return text;
  3. 上記スニペット内の <TODO: REPLACE SELECTOR> を、ステップ1でメモしたCSSセレクターに置き換えてください。