It's more safety to use locator in playwright. You can try something like that.

const someFunc = async () => {
    const table = await page.locator('#txnHistoryList > tbody')
    const arrayData = []
    const isVisibleTable = await table.isVisible()
    if (isVisibleTable) {
        const rows = table.locator('tr')
        const rowsCount = await rows.count()

        for (let i = 0; i < rowsCount; i += 1) {
            const row = rows.nth(i)
            const tdLocator = row.locator('td')
            const tdLocatorCount = await tdLocator.count()
            const arrays = {}
            if (tdLocatorCount > 2) {
                for (let j = 0; j < tdLocatorCount; j += 1) {
                    switch (j) {
                        case 1: {
                            const date = await tdLocator.nth(j).innerText()
                            arrays.date = date ? date.toString().trim() : ''
                            break
                        }
                        case 2: {
                            const transaction = await tdLocator.nth(j).innerText()
                            arrays.transaction = transaction ? transaction.toString().trim() : ''
                            break
                        }
                        case 4: {
                            const type = await tdLocator.nth(j).innerText()
                            arrays.type = type ? type.toString().trim() : ''
                            break
                        }
                        case 5: {
                            const paymentAmount = tdLocator.nth(j).innerText()
                            arrays.payment_amount = paymentAmount ? paymentAmount.toString().trim() : ''
                            break
                        }
                        case 6: {
                            const balance = tdLocator.nth(j).innerText()
                            arrays.balance = balance ? balance.toString().trim() : ''
                            break
                        }
                        default:
                            continue
                    }

                    arrayData.push(arrays)
                }
            }
        }
    }
    return arrayData
}

Docs: https://playwright.dev/docs/api/class-locator

Answer from Stanislav Taran on Stack Overflow
🌐
Playwright
playwright.dev › evaluating javascript
Evaluating JavaScript | Playwright
const data = 'some data'; // Pass |data| as a parameter. const result = await page.evaluate(data => { window.myApp.use(data); }, data); Playwright evaluation methods like page.evaluate() take a single optional argument.
🌐
Playwright
playwright.dev › page
Page | Playwright
Script to be evaluated in the page.
🌐
Medium
adequatica.medium.com › simple-examples-of-using-playwright-evaluate-method-9b00d01cadc1
Examples of Using Playwright Evaluate Method | by Andrey Enin | Medium
January 18, 2026 - test('Should copy text into the clipboard', async () => { const pageObjectModel = new PageObjectModel(page); await pageObjectModel.clickOnCopyButton(); const clipboardText = await page.evaluate('navigator.clipboard.readText()'); expect(clipboardText, 'Should have copied text in the clipboard').toBe('Foo bar'); }); Note, for this action, you need to update your Playwright config — grant permission to the browser context to read from the clipboard: use.permissions: ['clipboard-read'].
🌐
Playwright
playwright.dev › evaluating javascript
Evaluating JavaScript | Playwright Python
# A primitive value. page.evaluate('num => num', 42) # An array. page.evaluate('array => array.length', [1, 2, 3]) # An object. page.evaluate('object => object.foo', { 'foo': 'bar' }) # A single handle. button = page.evaluate_handle('window.button') page.evaluate('button => button.textContent', button) # Alternative notation using JSHandle.evaluate.
🌐
BrowserStack
browserstack.com › home › guide › understanding evaluate() method in playwright
Understanding evaluate() method in Playwright | BrowserStack
January 13, 2026 - The evaluate() method in Playwright is used to run JavaScript code within the browser context. By executing code directly in the page, you can interact with the page’s DOM, retrieve values, and manipulate page content in ways that would be ...
🌐
Playwright
playwright.dev › evaluating javascript
Evaluating JavaScript | Playwright Java
Object result = page.evaluate("data => {\n" + " window.myApp.use(data);\n" + "}", data); Playwright evaluation methods like Page.evaluate() take a single optional argument. This argument can be a mix of Serializable values and JSHandle instances.
🌐
Playwright
playwright.dev › page
Page | Playwright Python
Script to be evaluated in all pages in the browser context.
Find elsewhere
🌐
Codekru
codekru.com › home › evaluate() method in playwright java
evaluate() method in Playwright Java - Codekru
June 18, 2023 - To execute this code with Playwright, we can use the evaluate() method and pass the script as an argument, as demonstrated below. // executing Javascript code page.evaluate("console.log('Playwright Tutorial')");
🌐
Checkly
checklyhq.com › docs › learn › playwright › performance
Measuring Page Performance Using Playwright - Best Practices - Checkly Docs
Use this API to evaluate the Core Web Vital Cumulative Layout Shift (CLS). Layout shifts are no single event but event streams. To calculate CLS initialize a PerformanceObserver, observe layout-shift entries and sum all shifts.
🌐
WebScraping.AI
webscraping.ai › faq › playwright › how-to-evaluate-javascript-expressions-using-playwright
How to evaluate JavaScript expressions using Playwright? | WebScraping.AI
from playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.goto("https://example.com") # Get page title title = page.evaluate("() => document.title") print(f"Title: {title}") # Get current URL url = page.evaluate("() => window.location.href") print(f"URL: {url}") browser.close()
🌐
YouTube
youtube.com › watch
JavaScript Executor in Playwright | Execute JavaScript in Playwright with Java Using Evaluate - YouTube
In this video, you will learn how to execute JavaScript code seamlessly using Playwright in your Java-based automation projects. Now normal click on playwrig...
Published   December 3, 2024
🌐
GitHub
github.com › microsoft › playwright › issues › 32864
page.evaluate returns empty object · Issue #32864 · microsoft/playwright
September 28, 2024 - const input = await page.locator('css=input'); await input.focus(); const updatedConfig = await page.evaluate(() => { const config = { hasDropdownFlashed: false, observer: null }; const dialog = document.querySelector('complex-object-combobox').shadowRoot.querySelector('dialog'); config.observer = new MutationObserver((mutationList, observer) => { for (const mutation of mutationList) { if (dialog.style.display === '') { config.hasDropdownFlashed = true; } } }); config.observer.observe(dialog, { attributeFilter: ['style'] }); return config; }); console.log('updatedConfig: ', updatedConfig); // updatedConfig: { hasDropdownFlashed: false, observer: {} } await page.keyboard.type('a'); await page.waitForTimeout(1000); await page.keyboard.type('r'); await page.waitForTimeout(1000); // expect config.hasDropdownFlashed to be false
Author   okadurin
🌐
MiniMax
minimax.io › home › what's new › minimax m2.5: built for real-world productivity.
MiniMax M2.5: Built for Real-World Productivity. - MiniMax News | MiniMax
3 hours ago - Contains real questions from human experts, evaluating the model's multi-step information retrieval and reasoning capabilities when combined with complex web interactions. A Playwright-based browser tool suite is added on top of the WebExplorer ...
🌐
Playwright
playwright.dev › navigations
Navigations | Playwright
They fetch data lazily, populate UI, load expensive resources, scripts and styles after the load event was fired. There is no way to tell that the page is loaded, it depends on the page, framework, etc. So when can you start interacting with it? In Playwright you can interact with the page ...
🌐
Playwright
playwright.dev › pages
Pages | Playwright
It should be used to navigate to URLs and interact with the page content.
🌐
Playwright
playwright.dev
Fast and reliable end-to-end testing for modern web apps | Playwright
Playwright waits for elements to be actionable before performing actions. Assertions automatically retry until conditions are met. No artificial timeouts, no flaky tests. Each test gets a fresh browser context — equivalent to a brand new browser profile. Full isolation with near-zero overhead. Save authentication state once and reuse it across tests. Find elements with selectors that mirror how users see the page: getByRole, getByLabel, getByPlaceholder, getByTestId.