0
0

検索した文字列の隣をクリックする方法

Last updated at Posted at 2024-05-08
// 仮の変数にPower Automate Desktopから取得した文字列を設定
var searchText = "ここに検索文字列を入力"; 

// 検索文字列を含む<td>要素の左隣の<td>内の<a>タグをクリックする関数
function clickLinkInAdjacentLeftTd(searchText) {
    const tds = document.querySelectorAll('td');

    // 全ての<td>要素をループ
    for (let i = 0; i < tds.length; i++) {
        if (tds[i].textContent.includes(searchText) && i > 0) {
            const previousTd = tds[i - 1]; // 左隣の<td>要素を取得
            const link = previousTd.querySelector('a'); // 左隣の<td>内の最初の<a>要素を取得
            if (link) {
                link.click(); // <a>タグが存在すればクリック
                break; // 最初に見つかった要素のみ操作
            }
        }
    }
}

// 関数を呼び出す
clickLinkInAdjacentLeftTd(searchText);


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