我有以下标记,我正在尝试访问// Get the karma value for nick from the database.
func getKarma(nick string, db *sql.DB) string {
var karma int
rows, err := db.Query("SELECT SUM(delta) FROM karma WHERE nick = $1", nick)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
karmaStr := fmt.Sprintf("%s has no karma.", nick)
if rows.Next() {
rows.Scan(&karma)
karmaStr = fmt.Sprintf("Karma for %s is %d.", nick, karma)
}
return karmaStr
}
<button />
我有以下内容:
<ul class="flower-list">
<li ng-repeat="flower in model.flowers">
<img ng-src="flower.imgUrl">
<button ng-click="model.addToFlowerPot(flower)">Add</button>
</li>
</ul>
答案 0 :(得分:3)
如果数据来自服务,请检查是否存在延迟。您可以等到
获取数据 browser.waitForAngular()
答案 1 :(得分:1)
browser.waitForAngular()
不是处理此类案件的理想方式。量角器在内部等待角度事件循环。在这些情况下应该使用Expected Conditions
。
var EC = protractor.ExpectedConditions;
var flower = element.all(by.repeater('flower in model.flower')).first();
var addButton = flower.element(by.buttonText("Add"));
browser.wait(EC.visibilityOf(addButton), 5000); //wait for the button to become visible in dom
addButton.click();
或直接使用有效的承诺:
var flower = element.all(by.repeater('flower in model.flower')).first();
flower.then(function() {
return flower.element(by.buttonText("Add")).click();
});