Rayrun
← Back to Discord Forum

how to iterate through ul items

i have a div with id "#catlist-listview" and the div has an ul in it, so how can i iterate through the items in the ul from getting the div by id?

This thread is trying to answer question "How can I iterate through the items in a 'ul' list within a 'div' using the Playwright library in Python, considering the 'li' items are being added dynamically?"

14 replies
insane_rookstar
insane_rookstar

#catlist-listview ul li?

do i use page.locator() with that?

insane_rookstar
insane_rookstar

Yeah

insane_rookstar
insane_rookstar
for (const loc of await page.locator('...').all()) {
  // ...
}
@insane_rookstar: ahh im loving playwright already, very simple but adding more context: i am using the async api in python and i believe the li's are being added dynamically, so would that make the .all() unstable? or does playwright automatically handle that too?

ahh im loving playwright already, very simple

but adding more context: i am using the async api in python and i believe the li's are being added dynamically, so would that make the .all() unstable? or does playwright automatically handle that too?

insane_rookstar
insane_rookstar

dynamically? after your action like clicking somewhere?

insane_rookstar
insane_rookstar

then you have to wait for them, e.g. by waiting for the response from the API

it loads after you load the main page

insane_rookstar
insane_rookstar

so if you already waited for the ready state, it should be stable

does .all() do that?

insane_rookstar
insane_rookstar

try

it looks like it is, thanks for the help! :)

You gotta be careful with things like all() since they fire immediately. Sets up a race condition. It may work now, but you probably want to expect or wait for some state that indicates the list is ready before running all()

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.