如何解决 Selenium 错误 - “by.css(...).getText 不是函数”?

How to resolve Selenium error - " by.css(...).getText is not a function"?

我正在尝试使用 Selenium 比较 table 中存在的文本,但我的自动化测试失败并显示 by.css(...).getText is not a function。我该如何解决这个错误?

expect(by.css('table tr:nth-of-type(9) [colspan]').getText()).toEqual("This is test data.");

您刚刚错过了 element 功能。

应该是:

expect(element(by.css('table tr:nth-of-type(9) [colspan]')).getText()).toEqual("This is test data.");

或:

expect($('table tr:nth-of-type(9) [colspan]').getText()).toEqual("This is test data.");