codeception 中的 fillField 方法不起作用抛出 DOMXPath::query(): Invalid expression

Posted

技术标签:

【中文标题】codeception 中的 fillField 方法不起作用抛出 DOMXPath::query(): Invalid expression【英文标题】:fillField method in codeception not working throwing DOMXPath::query(): Invalid expression 【发布时间】:2014-05-23 19:12:26 【问题描述】:

$I->fillField("username", "test");

在运行验收测试时,出现以下错误:

抱歉,我无法填写“用户名”、“测试”字段: ErrorException: DOMXPath::query(): 无效的表达式

输入元素在表单内。我尝试将 id 添加到输入并使用 inpu 访问元素。但都返回了相同的错误。 “see” 方法正在工作..但不是 fillField 或 seeInField。

【问题讨论】:

同样的问题。我今天更新了作曲家 见:github.com/Codeception/Codeception/issues/1035 && github.com/symfony/symfony/pull/10987 【参考方案1】:

你必须告诉 codeception 它在寻找什么元素。

如果用户名是 id 则:

$I->fillField("#username", "test");

如果一个班级这样做:

$I->fillField(".username", "test");

或输入元素的 xpath:(例如 google.com 上的搜索字段)

$I->fillfield('//*[@id="gbqfq"]','my search text test');

【讨论】:

以上是关于codeception 中的 fillField 方法不起作用抛出 DOMXPath::query(): Invalid expression的主要内容,如果未能解决你的问题,请参考以下文章