diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index cf382f098..6bbb3e756 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -680,6 +680,10 @@ async function firstPageOnTop(page) { } async function setCaretAt(page, pageNumber, text, position) { + // Wait for the text layer to finish rendering before trying to find the span. + await page.waitForSelector( + `.page[data-page-number="${pageNumber}"] .textLayer .endOfContent` + ); await page.evaluate( (pageN, string, pos) => { for (const el of document.querySelectorAll(