剧作家在定位器中找到子元素



我正试图编写一个函数来查找定位器中的子元素,比如:

async findElements(locator: Locator){
return locator.querySelector(some/xpath/or/css);
}

但是,我看到querySelector在Locator中不可用。querySelector的等价物是什么?

我想明白了,

locator.locator(some/xpath/)

我刚刚开始与剧作家合作。因此,这可能不是我们正在寻找的确切答案。

我正在用现有的知识库学习剧作家。

[https://github.com/twerske/ng-tube/blob/main/src/app/video-grid/video-grid.component.html]

在这种情况下,我只想知道我正在拿回一张卡片列表。

<div class="videos-grid">
<mat-card *ngFor="let video of videos" class="video-card">

在这种情况下,我不需要父母的推荐信。我可以简单地按类引用孩子视频网格。这一切都存在于角的For循环中。我知道Svelte和其他框架以不同的方式迭代列表。

test.only('ngTube has header and cardList', async ({browser}) => {
const page = await browser.newPage();
const context = await browser.newContext();
await page.goto("http://localhost:4200/")
const title = await page.locator('.header-title').textContent();
const videoList = (await page.locator('.video-card').allTextContents()).length;
// await page.pause();
expect(title).toStrictEqual('ngTube');
expect(videoList).toBeGreaterThan(0)
})

因为我想要所有的文本内容,所以我可以用类名'.video card'.获得所有内容

我想我得到的是,只要你能访问一个标识符,你就应该能够直接访问它。随着我浏览更多的文档和场景,我将更新/添加到这个答案中。

最新更新