Codeception,从Cept文件执行任意xpath查询

时间:2018-12-19 23:35:42

标签: codeception

如何从接受Cept文件执行任意xpath查询? (并获得结果)

通过示例,“ see”方法对我没有帮助,因为根据文档:

Note that the search is done after stripping all HTML tags from the body,

“ See”仅在剥离的字符串中搜索。我正在寻找一种通用方法来执行我想要的所有类型的xpath查询。我该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以直接在Cept文件中使用的方法通常仅返回匹配节点的文本值或特定属性的值。 如果您足够了,可以使用grabTextFromgrabAttributeFromgrabMultiple

如果您想获得更多属性或做一些更复杂的事情,可以在辅助方法中使用_findElements

<?php
namespace Helper;

class Functional extends \Codeception\Module
{

    public function doSomethingWithElements()
    {
        $elements = $this->getModule('PhpBrowser')->_findElements('//body/h1');
        foreach ($elements as $element) {
            //do whatever you want with it
        }
    }
}
相关问题