我有以下代碼:
it('7.1.8 - In Platform admin could review all ongoing and published notifications', async () => {
const allNotificationList = await page.waitForXPath(
'//header[contains(@class,"ant-layout-header")]//ul[contains(@class,"Notifications_banner-notifications")]',
);
expect(allNotificationList.length).not.toBe(0);
});
allNotificationList 獲取 ul 標簽,我想檢查所選 ul 標簽下有多少 li 標簽。
有誰知道如何使用 Puppetter 實作這一目標?
uj5u.com熱心網友回復:
您可以使用page.$x(or someElement.$x) 回傳ElementHandle[](page.waitForXPath回傳單個ElementHandle):
const allNotificationList = await page.$x(
'//header[contains(@class,"ant-layout-header")]//ul[contains(@class,"Notifications_banner-notifications")]',
);
expect(allNotificationList.length).not.toBe(0);
我不認為它實際上在等待元素,所以你可能想先添加以下行:
await page.waitForXPath(
'//header[contains(@class,"ant-layout-header")]//ul[contains(@class,"Notifications_banner-notifications")]',
);
uj5u.com熱心網友回復:
我沒有用 Xpath 解決這個問題,但如果你愿意將 Xpath 塑造成 CSS 選擇器,那么以下將滿足你的需要。使用childElementCount.
const selector = 'header.ant-layout-header * ul.Notifications_banner-notifications'
const childCount = await page.$eval(selector, el => el.childElementCount)
expect(childCount).toBeGreaterThan(0)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/422952.html
標籤:
