剧作家单击下拉菜单中的按钮

playwright click a button inside a dropdown

这里是对象的html:

<div class="filter-component filter-component-1">
   <p class="usa-accordion__heading">
     <button aria-selected="false" class="filtered assignment usa-accordion__button filter-dropdown ds-c-button ds-u-padding-left--1 ds-u-padding-right--4 ds-u-padding-y--1" aria-expanded="false" aria-controls="a1">
       <span>Medicare-approved payment: Full Payment </span>
       <div class="filter-arrow down"></div>
     </button>
   </p>
</div>

我的目标是用 class filter-component-1 获取 div 并将其存储在变量中然后

1 单击 div 2 单击 div

中的按钮

我觉得我需要做一些类似的事情

A NOTE: I have altered how we structure these tests so that they run in aws lambda. The normal sytax of test('test description') etc does not work here. Hence the awaits. Please just focus on the playwright syntax line by line.

let dropdowndiv = await this.page.waitForSelector(".filter-component-1");

然后呢?

对不起,我对剧作家很陌生,而且文档几乎没用 =( https://playwright.dev/java/docs/selectors#selecting-elements-that-contain-other-elements

您不必select任何事情都按照您的计划去做:

点击下拉菜单: await page.click(".filter-component-1")

然后点击按钮 await page.click("button")

(请注意,此按钮在该页面上必须是唯一的,如果不是,您可以添加另一个 select 或使其更具体)

如果您真的想存储那个 div 那么:

let dropdowndiv = await this.page.locator(".filter-component-1");

await dropdowndiv.click()

您可以将此定位器用于其中的 select 按钮:

await dropdowndiv.locator("button").click()