Reputation: 117
I have a below grid
The html code is at pastebin.com/GBP3AZNQ
I want to verify whether "test123" is present. I want to traverse through each row of column master obligationname and look for the text test123.
Can anyone guide me how to do this?
Upvotes: 1
Views: 323
Reputation: 2547
Your requirement can be fulfilled by using element.all().each() method of Protractor API. Please follow below code. Put the locator which gives all rows of a particular column in the below code.It will work perfectly.
element.all(by.css('locatorwhichgiveallrows')).each(function(rowElement,
index) {
rowElement.getText().then(function (rowText) {
if(rowText=="test123"){
return true;}
});
}).then(function(isPresent){
console.log("test123 is Present"+isPresent);
});
Upvotes: 0
Reputation: 1383
You can take the parent class
and achieve this as follows:
element.all(by.xpath("//div[@class='ui-grid-cell-contents ng-scope ng-binding']")).getText().then(function (msg)
{
console.log("Grid contains" + msg);
expect(msg).toContain("test123");
}
If suppose the Master_obligation name is test_876
Then
var master_obligation_name= "test_876" ;
Suppose you are filling obligation_name as:
element(by.xpath("path to master_obligation text field")).sendKeys(master_obligation_name);
After creation of the row, validating the newly added row:
var row_check = element(by.xpath("//div[contains(text(),'test_876')]"));
if(row_check.isPresent())
{
row_check.getText().then(function (msg) {
console.log("Grid contains" + msg);
});
}
Happy Learning. :-)
Upvotes: 1
Reputation: 548
check this code out. it check if the given text is available in the table.
this.searchCourseGrid = function(course){
var row = element.all(by.css('css path to tr'));
var cells = row.all(by.tagName('td'));
var cellTexts = cells.map(function (cell) {
return cell.getText();
}).then(function(cellTexts){
expect(cellTexts).toContain(course);
});
};
Upvotes: 0