簡體   English   中英

檢查選擇器在testcafe中是否存在

[英]Check selector is exist or not in testcafe

現在我有一些角色用戶,每個角色在創建帳戶時都會有一些不同所以我有條件來檢查下拉列表是否存在

'''

  if(await t.expect(this.dynamicButtonDropdownByAttribute('originator-org-select-button').exists).ok()){
    await this.selectValueInDropdownByAttribute('originator-org-select-button' , 'ORG')
    await this.clickButtonByAttribute('originator-org-next-button')
  }

'''

當下拉列表存在時沒關系,但當不存在時,它仍然在 if 條件下運行代碼,所以我不確定為什么會這樣?

expect不返回斷言的結果; 它返回testController 多虧了它,您可以在鏈中運行操作。 因此,您需要像這樣從條件中刪除expect

if(await this.dynamicButtonDropdownByAttribute('originator-org-select-button').exists){
    await this.selectValueInDropdownByAttribute('originator-org-select-button' , 'ORG')
    await this.clickButtonByAttribute('originator-org-next-button')
}

暫無
暫無

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

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