Codeception $I->click(<button text>) 结果:[ErrorException] Undefined 属性: DOMDocument::$tagName

Codeception $I->click(<button text>) results in: [ErrorException] Undefined property: DOMDocument::$tagName

我正在使用 Codeception 2.2.6 来测试 Laravel 应用程序。我有一个简单的测试,它打开一个带有表单的页面,填写一些字段,然后单击一个按钮。当我 运行 测试时,它工作正常,直到单击步骤,然后失败并出现以下错误:

[ErrorException] Undefined property: DOMDocument::$tagName

堆栈跟踪显示错误是由 Codeception\Lib\InnerBrowser.php 中的 clickButton 方法引发的:

/**
 * Clicks the link or submits the form when the button is clicked
 * @param \DOMNode $node
 * @return boolean clicked something
 */
private function clickButton(\DOMNode $node)
{
    $formParams = [];
    $buttonName = (string)$node->getAttribute('name');
    $buttonValue = $node->getAttribute('value');

    if ($buttonName !== '' && $buttonValue !== null) {
        $formParams = [$buttonName => $buttonValue];
    }

    while ($node->parentNode !== null) {
        $node = $node->parentNode;
        if ($node->tagName === 'a') {
            $this->openHrefFromDomNode($node);
            return true;
        } elseif ($node->tagName === 'form') {
            $this->proceedSubmitForm(
                new Crawler($node),
                $formParams
            );
            return true;
        }
    }
    return false;
}

我还有其他类似的测试,在不同的页面上使用点击没有问题。谁能帮我找出导致错误的原因

问题是测试 运行 所在的页面无效 HTML。我有一个标签没有正确关闭。这导致 Codeception 的 DOM 爬虫失败。

编辑(下面是我的注释):

breaking HTML 具有以下基本结构:

    <div>  <!-- this should be inside the form -->
        <form> <!-- this should be outside the div -->
    </div>
    <button>The Button</button>
</form>