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

TestCafe - 如何在不通過(guò)測(cè)試的情況下檢查 Web 元素

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

問(wèn)題描述

我正在嘗試編寫(xiě)一個(gè)腳本,該腳本需要根據(jù) CSS 選擇器找到的特定瀏覽器對(duì)象是否存在來(lái)調(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ì)通過(guò)我們的無(wú)論如何都要進(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.

邏輯硬幣的兩面我都試過(guò)了:

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è)問(wèn)題,也感謝您學(xué)習(xí)和提高我的 Javascript 技能!

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

推薦答案

您可以通過(guò)以下方式檢查 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 - 如何在不通過(guò)測(cè)試的情況下檢查 Web 元素是否存在?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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 選擇器 - 查找沒(méi)有指定屬性的對(duì)象)
主站蜘蛛池模板: 一区二区三区国产视频 | 日韩在线视频一区二区三区 | 九九视频免费观看 | 天天做天天爱 | 欧美极品一区 | 久久精品综合 | 我想看毛片| 五月婷婷综合在线 | 性爱视频日本 | 免费在线毛片 | 久久久久国产一区二区三区 | 国产精品成人国产乱一区 | 中文精品一区 | 国产日产精品一区二区三区的介绍 | 国产精品一品二区三区的使用体验 | 欧美日韩亚洲天堂 | 久久精品一区二区 | 91成人精品一区在线播放 | 91精品久久久久 | 亚洲一区中文 | 欧美福利在线观看 | 一区二区亚洲 | 欧美在线一区二区 | 国产午夜精品久久 | 日本黄色中文字幕 | 欧美亚洲国产精品 | 亚洲精品在线看 | 成年免费视频黄网站在线观看 | 久久九九免费视频 | 日本精品国产 | 亚洲国产黄色 | 成人欧美日韩 | 亚洲www.| 69av在线| 国产人成一区二区三区影院 | 久在线 | 欧美精品久久久久久久 | 黄网站免费在线观看 | 免费在线观看黄色片 | 国产黄色精品 | 天天综合天天 |