#angular #typescript #protractor
#angular #машинописный текст #транспортир
Вопрос:
Я хочу получить все строки, которые я отфильтровал в 3-м столбце. Я прикрепил картинку для справочной структуры сайта, вот сам сайт http://juliemr.github.io/protractor-demo /
//I found this online, but its not working for me it still retrieve all the data from the table
tablefil(){
//third column id like to filter
var name = "11";
// This is like element.all(by.css(''))
return $$("table[class='table']").filter(function(row) {
// Get the second column's text.
return row.$$("td[class='ng-binding']").get(3).getText().then(function(rowName) {
// Filter rows matching the name you are looking for.
return rowName === name;
});
}).getText().then(function(text){
//Display rows that fits my filter above
console.log('n' text 'n')
})
}
[1]: https://i.stack.imgur.com/z8Heb.png
Комментарии:
1. Похоже, что изображение не прикреплено, должно ли оно быть? Также правильно ли говорить, что вы хотите, чтобы возвращалось содержимое всех строк, содержащих ’11’ в третьем столбце (результат)?
2. Извините, stackoverflow не позволил мне прикрепить изображение, но, пожалуйста, посмотрите ссылку под кодами, да, это правильно.
Ответ №1:
Две проблемы в вашем коде:
1) Неправильный css-селектор для поиска всех строк таблицы. Правильный: table[class='table'] tbody > tr
2) Индекс массива начинается с ‘0’, таким образом, для получения третьего столбца следует использовать row.$$("td").get(2)
tablefil(result){
return $$("table[class='table'] tbody > tr")
.filter(function(row) {
// find out which row's Result is equal to argument: result
return row.$$("td").get(2).getText().then(function(text) {
return !result || text.trim() === resu<
});
})
.each(function(row){
// read the text of 2nd column: Expression on matched row
row.$$("td").get(1).getText().then(function(text){
console.log('expression: ' text)
});
// or if you want to print the Expression and Result together
row.$$("td:nth-child(2),td:nth-child(3)").getText().then(function(texts){
console.log(texts[0], '=', text[1])
});
})
}
tablefil() // will print all rows
tablefil('11') // will only print row's Result == 11
Комментарии:
1. спасибо, но что, если бы я хотел получить только столбец выражения, у меня это не сработает var name = «11» возвращает элемент(by.css(«table[class=’table’] tbody > tr»)).element(by.css(«span[class=’ng-binding’]»)).filter(функция (строка) { возвращает строку.$$((«td[class =’ng-binding’]»)).get(1).getText().затем (функция (текст) { возвращаемый текст === имя }) }).getText().затем(функция (текст) { console.log(текст ‘n’) пусть split = text.toString().split(» «,100) пусть size = split.length; console.log(размер) })