最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Protractor test that an element is empty - Stack Overflow

programmeradmin0浏览0评论

<div id='messagesDiv'></div>

I want to test that this div element is empty.

var messagesDiv = element(by.id('messagesDiv'));
expect(messagesDiv).to...

How would I achieve that?

<div id='messagesDiv'></div>

I want to test that this div element is empty.

var messagesDiv = element(by.id('messagesDiv'));
expect(messagesDiv).to...

How would I achieve that?

Share Improve this question edited Nov 18, 2016 at 17:56 jeerbl 7,8675 gold badges26 silver badges39 bronze badges asked Oct 11, 2015 at 20:12 YorkshiremanYorkshireman 2,3432 gold badges23 silver badges38 bronze badges 4
  • 2 Check for .getInnerHtml() should do the trick – Michael Radionov Commented Oct 11, 2015 at 20:32
  • Please confirm what test framework you are using Jasmine, Mocha etc.. as the syntax might be different dependent on the framework. – markyph Commented Oct 11, 2015 at 20:41
  • test framework is Jasmine – Yorkshireman Commented Oct 12, 2015 at 17:37
  • Any answer actually answered your question? – jeerbl Commented Aug 17, 2016 at 8:29
Add a ment  | 

3 Answers 3

Reset to default 6

I think this:

expect(messagesDiv.getText()).toBe('');

should do the trick. More information here.

Try

expect (messagesDiv.text).toBe('')

expect(messagesDiv.getText()).toMatch(/^\s*$/); will handle spaces, tabs, line breaks, etc. that HTML treats as empty but really might not be in the raw HTML.

发布评论

评论列表(0)

  1. 暂无评论