Selenium Webdriver で特定の文字列を含む要素を見つける
XPath の contains() を使えば、特定の文字列が含まれる要素を見つけられる。
code:ts
import { By } from 'selenium-webdriver';
// 文字列がどこかしらの子要素に含まれる
// Document全体から見つける
const selector = By.xpath('//*contains(., "テキスト")')
// 特定のノード以下から見つける
const selector = By.xpath('//html/body/div/<...任意のxpath>/contains(., "テキスト")')
// 文字列をその要素のTextNodeが持つ
// Document全体から見つける
const selector = By.xpath('//*contains(text(), "テキスト")')
// 特定のノード以下から見つける
const selector = By.xpath('//html/body/div/<...任意のxpath>/contains(text(), "テキスト")')
contains - XPath | MDN
#selenium
Created by tamuraryoya