我希望我对这个问题的表达是正确的。基本上,我使用定位器来查找一组元素,然后在该组中查找特定的元素。
我对async-js和protractor-webdriver是个新手,但对js (一般)并不陌生,对其他webdriver实现也有一定的了解。代码可能是展示我想要做的事情的最好方式:
var findDatepickerDay = function(month, year, day) {
var tds = element.all(by.css('.ui-datepicker-calendar tbody td:not(.ui-datepicker-unselectable)'));
tds.then(function(tds) {
tds.map(function(td){
var my= {};
return td.getAttribute('data-month').then(function (m) {
my.month = m;
}).then(function(m) {
td.getAttribute('data-year').then(function (y) {
my.year = y;
}).then(function() {
if (my.month == month && my.year == year) {
// console(my); // this returns the anticipated result
// a tag contains the day
/*td.findElement(by.tagName('a')).then(function(tag) {
// findElement is undefined
});*/
/*td.getDriver().findElement(by.tagName('a')).then(function(tag) {
// findElement is undefined
});*/
}
});
});
});
});
};我的主要问题是如何在td中找到元素?
第二个问题:有没有更好的方法。不幸的是,现在web上有如此多的实现,很难确定哪种方法是有效的,2)是当前的,3)最佳实践。每次我遇到问题,我就开始研究,结果发现我需要安装一些新的库(我的包列表一夜之间从3-10个跳到了10个)。
我使用的是: protractor (2.5.1),它依赖于selenium-webdriver (2.47.0)
感谢您的帮助。谢谢。
发布于 2016-04-16 02:28:01
这可能不是一个确切的答案,但希望能为您指明正确的方向。今天早些时候,我正在使用一张表,我需要在一张表下抓取所有的<tr>(而不是您的<td>)。
var table = element(by.css('#tableID'));
table.all(by.css('tbody tr')).count().then(function (count) {
expect(count).toEqual(3);
});你会想要用你想要实现的东西来代替count()。
在本例中,您需要知道<td>下的元素标记的类型,并将其链接起来,类似于我上面所做的操作。
table.all(by.css('tbody tr td **whatever Element tag**')).then(function() {}至于链接,它可以处理多个元素,如果你愿意,你可以在一行中完成。即
var something = element(by.css('.parent')).element(by.css('.child')).来源:https://angular.github.io/protractor/#/api?view=ElementFinder.prototype.element
此外,由于您正在使用量角器,因此建议您使用element而不是findElement -- findElement将从webdriver返回一个原始的webelement对象,而element将返回一个称为ElementFinder的webelement的量角器版本。
发布于 2016-04-18 22:05:00
我使用一些张贴的建议,并将过滤器移动到选择器中,从而能够将其带入下一阶段。我不确定多属性扇区是否适用于这些库,但我猜它们确实适用。事实证明,在这个实例中,我不需要进行链接。
var as = element.all(by.css('.ui-datepicker-calendar tbody td[data-month="'+month+'"][data-year="'+year+'"]:not(.ui-datepicker-unselectable) a'));
as.then(function(as) {
as.map(function(a) {
var my = {
month:month,
year:year
};
return a.getInnerHtml().then(function (d) {
my.day = d;
console.log(my)
});
});
});谢谢你的帮助。
https://stackoverflow.com/questions/36654111
复制相似问题