14
14

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 5 years have passed since last update.

SeleniumのWeb Driverで要素が無いことを確認する方法

Posted at

driver.findElementを使うと要素が無い場合NoSuchElementExceptionが発生してしまい、
テストに失敗する。
要素が無いことを確認するにはdriver.findElements(最後にsが付いている方)を使い、
サイズが0であることを確認する。
ただ、なぜか実行に時間がかかる、、、

    @Test
    public void test_1030() throws Exception {
        driver.get("http://localhost:8080/test/"); // 開く
        
        // HTML上にtestCssというスタイルの要素が無いことを確認する
        assertEquals(
                0,
                driver.findElements(By.className("testCss")).size());

    }


14
14
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
14
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?