最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在codeceptjs中调试和使用grabAttributeFrom?

运维笔记admin8浏览0评论

如何在codeceptjs中调试和使用grabAttributeFrom?

如何在codeceptjs中调试和使用grabAttributeFrom?

在我的例子中,页面中的所有标识符都是动态生成的。所以我不能使用xpath。

我在文档中找到了方法:grabAttributeFrom

  • 当我在--debug模式下使用cmd时,我怎么能看到里面的内容?
  • 当我搜索输入时,我可以使用grabAttributeFrom从页面中提取xpath吗?
  • 我怎样才能访问具有名称的输入,并且它们的xpath动态生成,我不能使用xpath?

我试过这段代码:

I.fillField(locate('input').inside('.jq-panel-body-default').at(2),'John');

但它不正确并生成异常:

 FAIL  Field "{"type":"xpath","output":null,"strict":true,"locator":{"xpath":".//input[ancestor::*[contains(concat(' ', normalize-space(./@class), ' '), ' jq-panel-body-default ')]][position()=2]"},"value":".//input[ancestor::*[contains(concat(' ', normalize-space(./@class), ' '), ' jq-panel-body-default ')]][position()=2]"}" was not found by text|CSS|XPath
回答如下:
  1. 当我在--debug模式下使用cmd时,我怎么能看到里面的内容?

里面..什么?如果要记录属性值,请抓取并记录:

Scenario("test", async (I) => {
  ...
  const attributeValue = await I.grabAttributeFrom(<locator>, <attribute>);
  console.log(attributeValue);
  ...
});
  1. 当我搜索输入时,我可以使用grabAttributeFrom从页面中提取xpath吗?

grabAttributeFrom用于获取属性值,而不是用于xpath查找。但是如果你问,你可以在定位器参数中使用xpath,是的,你可以。

  1. 我怎样才能访问具有名称的输入,并且它们的xpath动态生成,我不能使用xpath?

这还不足以问你。分享一些DOM部分或东西来理解。如果您的意思是name属性,您可以按名称使用过滤://input[@name="<your element name>"]

发布评论

评论列表(0)

  1. 暂无评论