【问题标题】:Codeception $I->click(<button text>) results in: [ErrorException] Undefined property: DOMDocument::$tagNameCodeception $I->click(<button text>) 导致:[ErrorException] Undefined property: DOMDocument::$tagName
【发布时间】:2016-11-28 17:06:25
【问题描述】:

我正在使用 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;
}

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

【问题讨论】:

    标签: domdocument codeception


    【解决方案1】:

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

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

    破坏性的 HTML 具有以下基本结构:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 2022-12-02
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    相关资源
    最近更新 更多