Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the text value of element in ngScenario

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to get the text value of element in ngScenario". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to get the text value of element in ngScenario.

In the ngScenario test of AngularJS, we sometimes need to do some special processing on the returned values and then compare them.

For example, we verify that the value of select is abcd

Expect (element ("select"). Text ()) .tobe ("abcd")

But you can use jquery to find that the value of this select is

\ n abc\ n

There will be more white space characters before and after. What we need to do is to trim it first, and then compare it with abcd.

Expect (_ .str.trim (element ("select"). Text ()) .tobe ("abcd")

Note that _ .str.trim is provided by Underscore.String.

But this doesn't work. The _ .str.trim function receives a promise object, so there is no text value in it.

To get the value correctly, some improvements need to be made. There are some discussions here, which can be referred to:

Var textPromise = element ('select') .query (function (nameElement, done) {var text = _ .str.trim (nameElement.text ()); / / Can finally access this guy! / / The first param null indicates a nominal execution, the second param is a return of sorts done (null, text);}); / / Passes expect (textPromise) .tobe (' abcd')

In this way, through the function query, you can get the real value of text.

At this point, I believe you have a deeper understanding of "how to get the text value of element in ngScenario". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report