* {{> waitForText }}
(text, sec = null, context = null)
| 2581 | * {{> waitForText }} |
| 2582 | */ |
| 2583 | async waitForText(text, sec = null, context = null) { |
| 2584 | const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout |
| 2585 | let waiter |
| 2586 | |
| 2587 | const contextObject = await this._getContext() |
| 2588 | |
| 2589 | if (context) { |
| 2590 | const locator = new Locator(context, 'css') |
| 2591 | if (locator.isCSS()) { |
| 2592 | waiter = contextObject.waitForFunction( |
| 2593 | (locator, text) => { |
| 2594 | const el = document.querySelector(locator) |
| 2595 | if (!el) return false |
| 2596 | return el.innerText.indexOf(text) > -1 |
| 2597 | }, |
| 2598 | { timeout: waitTimeout }, |
| 2599 | locator.value, |
| 2600 | text, |
| 2601 | ) |
| 2602 | } |
| 2603 | |
| 2604 | if (locator.isXPath()) { |
| 2605 | waiter = contextObject.waitForFunction( |
| 2606 | (locator, text, $XPath) => { |
| 2607 | eval($XPath) |
| 2608 | const el = $XPath(null, locator) |
| 2609 | if (!el.length) return false |
| 2610 | return el[0].innerText.indexOf(text) > -1 |
| 2611 | }, |
| 2612 | { timeout: waitTimeout }, |
| 2613 | locator.value, |
| 2614 | text, |
| 2615 | $XPath.toString(), |
| 2616 | ) |
| 2617 | } |
| 2618 | } else { |
| 2619 | waiter = contextObject.waitForFunction(text => document.body && document.body.innerText.indexOf(text) > -1, { timeout: waitTimeout }, text) |
| 2620 | } |
| 2621 | |
| 2622 | return waiter.catch(err => { |
| 2623 | throw new Error(`Text "${text}" was not found on page after ${waitTimeout / 1000} sec\n${err.message}`) |
| 2624 | }) |
| 2625 | } |
| 2626 | |
| 2627 | /** |
| 2628 | * Waits for a network request. |
nothing calls this directly
no test coverage detected