最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - playwright click a button inside a dropdown - Stack Overflow

programmeradmin4浏览0评论

here is the html of the object:

<div class="filter-ponent filter-ponent-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>

my goal is to grab the div with the class filter-ponent-1 and store it in a variable to then

1 click that div 2 click the button in that div

I feel like i need to do something like

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-ponent-1");

but then what?

sorry im very new to playwright and the docs are pretty much useless =( /java/docs/selectors#selecting-elements-that-contain-other-elements

here is the html of the object:

<div class="filter-ponent filter-ponent-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>

my goal is to grab the div with the class filter-ponent-1 and store it in a variable to then

1 click that div 2 click the button in that div

I feel like i need to do something like

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-ponent-1");

but then what?

sorry im very new to playwright and the docs are pretty much useless =( https://playwright.dev/java/docs/selectors#selecting-elements-that-contain-other-elements

Share Improve this question edited Jan 5, 2022 at 21:07 corporate chris asked Jan 5, 2022 at 21:01 corporate chriscorporate chris 892 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You dont have to select anything just do as You planned:

Click on dropdown: await page.click(".filter-ponent-1")

Then Click on button await page.click("button")

(Note that this button must be unique on that page, if its not you can add another selector to make it more specific)

If You really want to store that div then:

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

await dropdowndiv.click()

You can use this locator to select button inside it:

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

发布评论

评论列表(0)

  1. 暂无评论