protractor how to get text from div?
12,242
Target all messages available inside the container
var messageElms = $('.container').all(by.binding('message'));
Assuming you expect only 1 message:
expect(messageElms.count()).toBe(1);
Assuming you expect that Hello to be the first message:
expect(messageElms.get(0).getText()).toEqual('Hello this is it!');
Comments
-
Pindakaas almost 2 years
Trying to get the text inside my div:
<div class="ng-scope ng-binding"> Hello this is it! </div>
In my jasmine script I have (using xpath):
var helloTxt=driver.findElement(by.xpath('//*[@id="top"]/div/div/div[3]/div[2]/div/div[1]/div[1]/div/div')); expect(helloTxt.getText()).toBe('Hello this is it!');
the code looks like this:
<div class="container"> <div data-ng-repeat="message in getMessages() track by $index"> {{message}} </div> </div>
How can I check get the messages in
{{message}}
? Is there another way to access this div without using xpath? Or how can I fix this?