MCPcopy
hub / github.com/codeceptjs/CodeceptJS / switchToPreviousTab

Method switchToPreviousTab

lib/helper/Playwright.js:1882–1897  ·  view source on GitHub ↗

* Switch focus to a particular tab by its number. It waits tabs loading and then switch tab * * ```js * I.switchToPreviousTab(); * I.switchToPreviousTab(2); * ``` * @param {number} [num=1]

(num = 1)

Source from the content-addressed store, hash-verified

1880 * @param {number} [num=1]
1881 */
1882 async switchToPreviousTab(num = 1) {
1883 if (this.isElectron) {
1884 throw new Error('Cannot switch tabs inside an Electron container')
1885 }
1886 const pages = await this.browserContext.pages()
1887 const index = pages.indexOf(this.page)
1888 this.withinLocator = null
1889 const page = pages[index - num]
1890
1891 if (!page) {
1892 throw new Error(`There is no ability to switch to previous tab with offset ${num}`)
1893 }
1894
1895 await this._setPage(page)
1896 return this._waitForAction()
1897 }
1898
1899 /**
1900 * Close current tab and switches to previous.

Callers 1

closeCurrentTabMethod · 0.95

Calls 2

_setPageMethod · 0.95
_waitForActionMethod · 0.95

Tested by

no test coverage detected