如何使用量角器验证具有类的元素是否出现

时间:2017-10-30 16:54:01

标签: javascript selenium protractor

我需要验证这个div出现,但它不起作用。我试图通过classeName使用。

<div aria-live="polite" class="ui-growl-item-container ui-state-highlight ui-corner-all ui-shadow ui-growl-message-sucess">

我的代码:

const validacao =  element(by.className('.ui-growl-item-container.ui-state-highlight.ui-corner-all.ui-shadow.ui-growl-message-sucess'));

expect (validacao.isPresente()).ToBeTruthy();

Protactor一直让我失意。 为什么呢?

1 个答案:

答案 0 :(得分:1)

实际上你是在传递CSS选择器,而不是类名。

要使其按预期工作,请尝试

scala> val x: Any = m.getValue[Int]("2").get
x: Any = two

scala> x.getClass
res2: Class[_] = class java.lang.String

scala> val y: Any = m.getValue[Int]("1").get
y: Any = 1

scala> y.getClass
res3: Class[_] = class java.lang.Integer

scala> val z = m.getValue[Int]("1").get
z: Int = 1

scala> z.getClass
res4: Class[Int] = int

With Worksheet(WorkSheet)
.Range(.Cells(2,1).End(XlDown),.Cells(2,58)).Select
End With
Selection.ClearContents

或者您可以将单个班级名称传递给const validacao = element(by.css('.ui-growl-item-container.ui-state-highlight.ui-corner-all.ui-shadow.ui-growl-message-sucess'));

const validacao =  $('.ui-growl-item-container.ui-state-highlight.ui-corner-all.ui-shadow.ui-growl-message-sucess');