计算一个类在带有 codeception 的页面中出现的次数

ces*_*nux 2 codeception

我正在使用 Codeception 运行验收测试,我需要计算带有“.remove”类的按钮在一页中出现的次数。此类按钮位于 html 表内,计数取决于购物车中的商品数量。
以下是我尝试使用的代码:

    $I->amOnPage("/cart/");
    $table = $I->grabTextFrom(".//*[@id='cart']/table");
    $rows = explode("<tr>", $table);
    $rcount = count($rows);
    while ($rcount >= 0) {
        $I->click(".remove");
        $rcount--;
    }
    $I->see("Your shopping cart is empty.");
Run Code Online (Sandbox Code Playgroud)

Bor*_*sky 5

我知道这有点晚了,但是您应该按照此处的说明尝试 $I->seeNumberOfElements:

http://codeception.com/docs/modules/WebDriver#seeNumberOfElements