[英]How to check nested shadow elements using cypress.io
如何定位嵌套陰影 DOM 內的搜索框?
到目前為止,我已經嘗試了幾種不同的定位方法,下面是其中之一,但沒有奏效:
定位器:
//Shadow roots
const SDW_MAINAPP_G1 = "main-app"
const SDW_VOYAGETOPBAR_G2A = "voyage-topbar"
const SDW_VOYAGEPANEL_G2B = "voyage-float-panel"
const SDW_VESSELLIST_G3B = "voyage-vessel-list"
const SDW_VOYAGEFILTER_G4B1 = "voyage-filter"
const SDW_LISTSORT_G4B2 = "voyage-vessel-list-sort"
//Left Panel - Search Box
const INP_SEARCH_VESSEL = "#filter"
實際代碼:
class SearchComponents {
static validateSearchBar() {
cy.get(SDW_MAINAPP_G1)
.shadow()
.find(SDW_VOYAGEPANEL_G2B)
.find(SDW_VESSELLIST_G3B)
.find(SDW_VOYAGEFILTER_G4B1)
.find(INP_SEARCH_VESSEL)
.should('be.visible')
.should('be.enabled')
}
//...
}
嵌套的 shadow-root 使得很難確定應該在哪里添加.shadow()
命令,但是您可以在 配置(cypress.json) 中全局啟用 shadow DOM 搜索
包括ShadowDom
是否遍歷 shadow DOM 邊界並將 shadow DOM 內的元素包含在查詢命令的結果中(例如 cy.get())
cypress.json
{
...
includeShadowDom: true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.