LoginSignup
12
11

More than 5 years have passed since last update.

selenium-webdriverテクニック集

Posted at

DOM要素の有無によって分岐する

element_exists.js
driver.findElements(ElementLocator).then(function (elements) {
  if (elements.length) {
    //あり
  } else {
    //なし
  }
});

Select要素を選択

select.js
driver.findElement(By.xpath('//select[@name="名前"]/option[@value="値"]')).click();

innerTextで要素を取得

innerText.js
driver.findElement(By.xpath('//*[text()="値"]'));

Xpathでのclass指定

className.js
driver.findElement(By.xpath('//*[contains(@class,"クラス名")]'));

※部分一致なので完全ではないので、なるべく特定できるもので指定すること。

12
11
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
12
11