Reputation: 41
I am trying to test a dynamic web table using protractor and trying to find the count of headers, rows and cols but always getting 0 as the count var x = element.all(by.xpath('//table//thead//tr//th'))
x.count().then(function(c){
console.log(c);
});
I tried using element.all(by.css ) as well and it returns the same , can anyone help? I used selenium and able to retrieve the value, so xpath is not wrong, but I have to use protractor to fetch the same. Selenium script which is working List col = driver.findElements(By.xpath("//div[@class='table-wrapper']//table//thead//tr/th")); System.out.println(col.size());
Upvotes: 0
Views: 458
Reputation: 2734
In general, you should avoid xpath
since it's very inefficient.
This should work for you:
var table = element(by.css('table.table'));
table
.element(by.css('thead'))
.all(by.css('tr th'))
.count()
.then(function(count) {
console.log('count:',count);
});
Upvotes: 0
Reputation: 1442
Try the below code
var x = await element.all(by.css('table[title="status"]'))
//Add wait if the table take more time to load
x.count().then(function(c){
console.log(c);
});
Upvotes: 0