Expect无法验证内部HTML

时间:2015-06-06 00:40:45

标签: jquery selenium testing jasmine protractor

由于某些原因,我在量角器中的断言失败了,我想要做的是从元素中获取innerHTML(text):

var stuff = $('css').html();

期待(东西).toBe(“内部HTML文本在这里”);

我确认$().html()会在控制台上生成我想要的文本,我的期望声明有什么问题?

  

TypeError:Object [object Object]没有方法'html'

2 个答案:

答案 0 :(得分:4)

使用getInnerHtml()

expect($('.your-css').getInnerHtml()).toBe('your inner html');

http://angular.github.io/protractor/#/api?view=webdriver.WebElement.prototype.getInnerHtml

答案 1 :(得分:2)

错误消息表明无论对象" $"返回,它没有" html"方法

如果你期望" $"作为jQuery的引用,然后尝试使用" jQuery"显然,例如。

Standard ML of New Jersey v110.76 [built: Thu Feb 19 00:37:13 2015]
- fun descs ss = map Socket.sockDesc ss ;;
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
val descs = fn : ('a,'b) Socket.sock list -> Socket.sock_desc list
- fun selecting server clients =
    let val { rds, exs, wrs } = Socket.select {
        rds = descs [server],
        wrs = descs [],
        exs = descs clients,
        timeout = (SOME (Time.fromSeconds 10))
        }
    in
    (rds, wrs, exs)
    end ;;
= = = = = = = = = [autoloading]
[autoloading done]
val selecting = fn
  : ('a,'b) Socket.sock
    -> ('c,'d) Socket.sock list
       -> Socket.sock_desc list * Socket.sock_desc list * 
          Socket.sock_desc list
- 

此外,我不确定上述声明中的选择器是否是您的实际选择器,如果是,它正在寻找" css"看似不对的元素。你可能想看一下。