Rayrun
← Back to Discord Forum

"section" HTML tags?

I am scraping data from a web page where the HTML source code shows a lot of "section" elements.... Is there a way to use Playwright locator to locate these elements and act on other contained HTML elements therein?

<section id="main"> <section class="master-form-container"> <section id="report" class="" role="form"> <section class="question-block instructions" question-type="instructions" data-index="0"> <h2 class="question" id="question0">360 Degree Feedback</h2>

This thread is trying to answer question "Is there a way to use Playwright locator to locate 'section' elements and interact with contained HTML elements?"

5 replies

Yes, if you want to make your locators based on elements you should use CSS locator https://playwright.dev/docs/other-locators#css-locator

It's a CSS selector + some custom pseudo-elements like :has-text or :right-of

However, the recommendations are to use user-facing attributes i.e. getByRole and other Testing Library-inspired syntax

See best practices
https://playwright.dev/docs/best-practices#use-locators

You should probably use codegen to kick-start your automation !

Still wonder if an XPath would actually work better here? //section will get you all at any depth...

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 [email protected].