简体   繁体   English

Codecept可以看到RSS feed(XML)中的元素吗?

[英]Can codecept see elements in RSS feeds (XML)?

I have an RSS feed which should have only 1 'item' in it. 我有一个RSS feed,其中应该只有1个“项目”。 I know that I can do I.see() to check that any number exists; 我知道我可以做I.see()来检查是否存在任何数字; but is it possible to check if exactly 1 exists? 但是可以检查是否确切存在1吗?

I know for elements (in html) I have much more flexibility than simply I.see(). 我知道元素(在html中)比简单I.see()具有更大的灵活性。 Is it possible to see xml as elements? 是否可以将xml视为元素?

const DOMParser = require('xmldom').DOMParser;
let parser = new DOMParser();
let elementTagName = "rss"; // set tag of your element here
let xmlXpath = "//body/pre";

I.waitForElement(xmlXpath);
let innerText = await I.grabTextFrom(xmlXpath);
let documentCustom = parser.parseFromString(innerText, "text/xml");
let documentCustomGetElement = documentCustom.getElementsByTagName(elementTagName)[0].childNodes; // your element here

You can try it for this rss-feed . 您可以为此rss-feed尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM