Reputation: 433
I'm trying to get the text value of an element <span>
but it doesn't return anything with .getText()
`
//spec
var statPage = require('something');
describe('Start', function () {
describe('Setup', function () {
it('test quality', function(){
new statPage().quality();
});
});
});
//page object
Sender.prototype.quality = function () {
browser.ignoreSynchronization = true;
this.verifyPageUrl();
this.verifyTabName();
};
Sender.prototype.verifyTabName = function () {
console.log("inside verifyTabName()");
var EC = protractor.ExpectedConditions;
var tab = element(by.css("span.active-tab-head"));
browser.wait(EC.textToBePresentInElement(tab, 'u4uvpzn4'), 5000).then(function(){
console.log('inside browser wait');
});
tab.getText().then(function(tabFullName) {
console.log('tab name is : ' + tabFullName);
});
};
Sender.prototype.verifyPageUrl = function () {
browser.getCurrentUrl().then(function(text){
console.log('this is the right page : ' + text);
});
};
Upvotes: 1
Views: 504
Reputation: 433
Something weird was happening coz protractor was not even recognizing browser.pause()
But, reinstalling protractor fixed the issues!
Upvotes: 0
Reputation: 770
You can make your code more dynamic by trying:
var tabName = element(by.css('.tab-head.active-tab-head'));
The only other issue I could think of off-hand is that you may not have any tabs set to .active-tab-head, which would return an empty string.
Upvotes: 0
Reputation: 473873
The code you've presented, looks correct and, I suspect, there could be a timing issue. Let's use textToBePresentInElement
Expected condition and wait for u4uvpzn4
text to be present inside an active tab:
var EC = protractor.ExpectedConditions;
var tab = element(by.css("span.active-tab-head"));
browser.wait(EC.textToBePresentInElement(tab, 'u4uvpzn4'), 5000);
tab.getText().then(function(tabFullName) {
console.log('tab name is : ' + tabFullName);
});
Upvotes: 1