簡體   English   中英

無法使用 Nightwatch 定位列表元素

[英]Unable to locate list elements using Nightwatch

我有一些列表元素:

< button id={"productBook"} className="fito-btn fito-btn-long" style={this.props.styles.btnBrandRevers} onClick={this.props.onOfferSelect.bind(null, product)}>
 < FormattedMessage id='app.Book' defaultMessage='Book' />
< /button>

當斷言 id 為productBook的元素時:

.assert.visible('button[id=productBook]')

我收到一個錯誤:

Testing if element <button[id=productBook]> is visible. Element could not be located. - expected "true" but got: "null"

我不明白為什么這不適用於這個特定元素,而它適用於其他元素。 是否有一些不同的方式需要驗證列表元素? 請幫忙。

嘗試使用簡寫#作為 id:

assert.visible('button#productBook')

或者

assert.visible('#productBook')

根據您共享的 HTML, <button>id屬性是動態生成的。 所以你可能無法通過id斷言 相反,您可以通過以下定位器策略斷言FormattedMessage可見性

  • xpath

     //button[@class='fito-btn fito-btn-long']/FormattedMessage[@id=\\"app.Book\\"][@defaultMessage='Book']

請嘗試以下操作:

.assert.not.elementPresent('tr[...]')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM