久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

TestCafe - 如何在不通過測試的情況下檢查 Web 元素

TestCafe - How to check if a web element exists or does not exist without failing the test?(TestCafe - 如何在不通過測試的情況下檢查 Web 元素是否存在?)
本文介紹了TestCafe - 如何在不通過測試的情況下檢查 Web 元素是否存在?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試編寫一個(gè)腳本,該腳本需要根據(jù) CSS 選擇器找到的特定瀏覽器對(duì)象是否存在來調(diào)整其工作流行為.

I'm trying to write a script that needs to adapt it's workflow behavior depending on whether a particular browser object found by CSS selector exists or does not exist.

我不想使用 document.getElementByID 方法,因?yàn)檫@在技術(shù)上不是 CSS 選擇器,而且我們的整個(gè)企業(yè)都在 CSS 選擇器上進(jìn)行了標(biāo)準(zhǔn)化,所以除了 CSS 選擇器之外的任何遍歷 DOM 的東西都不會(huì)通過我們的無論如何都要進(jìn)行代碼審查.

I do not want to use a document.getElementByID method as this is not technically a CSS selector, and our entire enterprise is standardized on CSS selector so anything that walks the DOM other then a CSS selector won't make it past our code review process anyway.

var thing = await things.thingSelector(thingName);
if (await t.expect(thing.exists).notOk()) {
   await t.click(things.OpenThing(thingName));
} else {
   return false;
}
return true;

thingSelector 在哪里:

Where thingSelector is:

const thingSelector = name =>
  Selector('p.thing-header-title span')
    .withText(name)
    .parent('div.thing');

OpenThing 在哪里:

Where OpenThing is:

const OpenThing = name =>
    thingSelector(name)
        .find('a.thing-footer-item')
        .withText('Open');

如果對(duì)象不存在并且我正在檢查它是否存在,或者如果對(duì)象存在并且我正在檢查它不存在,以及對(duì)象存在的情況,我需要能夠繼續(xù)執(zhí)行不存在,不存在,對(duì)象不存在,我正在檢查它是否不存在.

I need to be able to continue execution if the object is not there and I'm checking that it exists, or if the object is there and I'm checking that it does not exist, and also the cases where the object is not there and it does not exist and the object is not there and I'm checking that it does not exist.

在所有情況下,我仍然需要繼續(xù)工作流程.

In all cases I still need to proceed with the workflow.

邏輯硬幣的兩面我都試過了:

I've tried both sides of the logic coin:

if (!await t.expect(thing.exists).ok())

if (await t.expect(thing.exists).notOk())

如果上述其中一項(xiàng)在一種情??況下未失敗,則在另一種情況下將失敗,而在第一個(gè)未失敗的情況下,另一項(xiàng)將失敗.我需要一些能給我邏輯的東西,但永遠(yuǎn)不會(huì)使腳本執(zhí)行失敗,并且仍然允許我根據(jù)對(duì)象是否存在返回 True 或 False.

If one of the above doesn't fail in one scenario it will fail in the other, and the other one will fail in the scenario that the first one didn't fail. I need something that will give me the logic, but not ever fail the script execution and still allow me to return either True or False depending on if the object is present or not present.

提前感謝您幫助我解決了這個(gè)問題,也感謝您學(xué)習(xí)和提高我的 Javascript 技能!

Thank you in advance for helping me to solve this problem, and also to learn and grow in my Javascript skills!

推薦答案

您可以通過以下方式檢查 if 條件中的 async exists 屬性:

You can check the async exists property in the if condition in the following way:

if(await things.thingSelector(thingName).exists) {
    // do something 
} 

這篇關(guān)于TestCafe - 如何在不通過測試的情況下檢查 Web 元素是否存在?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結(jié)果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯(cuò)誤:當(dāng)使用 JS 刪除項(xiàng)目時(shí),first-child 不更新 display:block)
CSS: Select element only if a later sibling exists(CSS:僅當(dāng)存在較晚的兄弟時(shí)才選擇元素)
How to show the child div on mouse hover of parent div(如何在父div的鼠標(biāo)懸停時(shí)顯示子div)
How to properly escape attribute values in css/js attribute selector [attr=value]?(如何在 css/js 屬性選擇器 [attr=value] 中正確轉(zhuǎn)義屬性值?)
jQuery selectors - find objects without specified attribute(jQuery 選擇器 - 查找沒有指定屬性的對(duì)象)
主站蜘蛛池模板: 亚洲第一中文字幕 | 国产精品成人一区二区三区夜夜夜 | 成人不卡| 成人国产精品久久 | 欧美精品久久久久久久久老牛影院 | 中文字幕在线观看一区二区 | 精品国产1区2区3区 在线国产视频 | 精品欧美一区免费观看α√ | 奇米视频777 | 天天干精品 | 欧美一级一区 | 麻豆国产一区二区三区四区 | 国产成人99久久亚洲综合精品 | 久久亚洲一区二区 | 国产欧美三区 | 国产激情视频网站 | 国产精品欧美一区二区 | 国产成人免费视频网站视频社区 | 欧美9999| 欧美一区二区三区在线 | aaaaaaa片毛片免费观看 | 中文字幕精品一区久久久久 | 日本黄色免费大片 | 2019精品手机国产品在线 | 亚洲免费网| 欧美视频1 | 国产视频福利一区 | 中文字幕在线第二页 | 91免费在线| 欧美日韩精品一区二区三区视频 | 中文字幕一区在线观看视频 | 亚洲国产一区二区三区 | 亚洲福利| 成人精品在线观看 | 成人乱人乱一区二区三区软件 | 国产成人精品视频在线观看 | 免费av手机在线观看 | 亚洲视频在线播放 | 亚洲久草| 精品不卡 | 亚洲国产成人精品女人 |