我想知道是否有一种方法可以调用 casperjs getElementsInfo 两次,我尝试过执行类似于下面的操作,但没有成功。想知道是否有解决办法?
var rows = this.getElementsInfo('table.dateentrytable tr');
var cells = rows[0].getElementsInfo('td');
最佳答案
你不能,我为此类情况找到的解决方案使用 XPath 和 while 循环,例如,此代码循环遍历行数未定义的表:
i= 1;
var x = require('casper').selectXPath;
while (this.exists(x('/html/body/form/div[3]/div[4]/div/div/div/table/tbody/tr[' + i + ']/td[1]'))) {
this.echo(this.fetchText(x('/html/body/form/div[3]/div[4]/div/div/div/table/tbody/tr[' + i + ']/td[1]')));
this.echo(this.fetchText(x('/html/body/form/div[3]/div[4]/div/div/div/table/tbody/tr[' + i + ']/td[2]')));
i++;
}
在您的情况下,请使用 getElementInfo() 代替 echo()。
关于javascript - 是否可以对已通过 getElementsInfo 检索到的元素使用 getElementsInfo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51163933/