Rayrun
← Back to Discord Forum

How to get the value of "5" of this data-testid in Playwright?

<h1 class="MuiTypography-root MuiTypography-h1 css-zxlx67" data-testid="number">5</h1>

I tried: number = self.supervisor_page.RECEIVED_NUMBER.get_attribute("data-testid")

but getting timeout error, while it is there in the DOM: waiting for get_by_test_id("number")

This thread is trying to answer question "How can one extract the value '5' from a data-testid in Playwright using Python without encountering errors?"

4 replies

page.getByTestId('number').textContent() in node, should be somewhat similar in python

yes... it is closer, yet

number = page.locator(self.supervisor_page.RECEIVED_NUMBER).text_content()

returns error>

raise TypeError(f'Object of type {o.__class__.__name__} ' f'is not JSON serializable') E TypeError: Object of type Locator is not JSON serializable

what is self.supervisor_page.RECEIVED_NUMBER?

page.locator("h1").textContent()

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].