如何在Jasmine中通过类名获取Angular 2元素 [英] How to get Angular 2 element through class name in Jasmine
本文介绍了如何在Jasmine中通过类名获取Angular 2元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用
fixture.debugElement.query(By.css('h1'));
但是当我想要通过类名获取元素时我该怎么做。这样的东西
But what I should to do when I want get element through class name. Something like this
fixture.debugElement.query(By.css('class="name"'))
推荐答案
您使用 By.css
传递一个css选择器。所以你可以使用css的任何选择器,你可以使用 By.css
。并且类的选择器只是 .classname
(带句号)。
You use By.css
to pass a css selector. So any selector you can use with css, you can use with By.css
. And a selector for a class is simply .classname
(with period).
By.css('.classname') // get by class name
By.css('input[type=radio]') // get input by type radio
By.css('.parent .child') // get child who has a parent
这些只是一些例子。如果你知道css,那么你应该知道如何使用选择器。
These are just some example. If you know css, then you should know how to use selectors.
编辑:
要使用 By.css()
一定要确定到从'@ angular / platform-browser'导入{By};
这篇关于如何在Jasmine中通过类名获取Angular 2元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文