1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[31678],{22002:(e,t,i)=>{i.d(t,{R:()=>o,x:()=>a});var r=i(7378);const n={},s=r.createContext(n);function o(e){const t=r.useContext(s);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:o(e.components),r.createElement(s.Provider,{value:t},e.children)}},23280:(e,t,i)=>{i.r(t),i.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"api/browser/switchWindow","title":"switchWindow","description":"Switch focus to a particular tab / window.","source":"@site/docs/api/browser/_switchWindow.md","sourceDirName":"api/browser","slug":"/api/browser/switchWindow","permalink":"/docs/api/browser/switchWindow","draft":false,"unlisted":false,"editUrl":"https://github.com/webdriverio/webdriverio/edit/main/packages/webdriverio/src/commands/browser/switchWindow.ts","tags":[],"version":"current","frontMatter":{"id":"switchWindow","title":"switchWindow","custom_edit_url":"https://github.com/webdriverio/webdriverio/edit/main/packages/webdriverio/src/commands/browser/switchWindow.ts"},"sidebar":"api","previous":{"title":"switchFrame","permalink":"/docs/api/browser/switchFrame"},"next":{"title":"throttle","permalink":"/docs/api/browser/throttle"}}');var n=i(86106),s=i(22002);const o={id:"switchWindow",title:"switchWindow",custom_edit_url:"https://github.com/webdriverio/webdriverio/edit/main/packages/webdriverio/src/commands/browser/switchWindow.ts"},a=void 0,c={},d=[{value:"Usage",id:"usage",level:2},{value:"Parameters",id:"parameters",level:2},{value:"Example",id:"example",level:2}];function w(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:"Switch focus to a particular tab / window."}),"\n",(0,n.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"await browser.switchWindow(matcher)\n"})}),"\n",(0,n.jsx)(t.h2,{id:"parameters",children:"Parameters"}),"\n",(0,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{children:"Name"}),(0,n.jsx)(t.th,{children:"Type"}),(0,n.jsx)(t.th,{children:"Details"})]})}),(0,n.jsx)(t.tbody,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"matcher"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"String, RegExp"})}),(0,n.jsx)(t.td,{children:"String or regular expression that matches either the page title or URL, the window name, or the window handle"})]})})]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",metastring:'title="switchWindow.js"',children:"it('should switch to another window', async () => {\n // open url\n await browser.url('https://google.com')\n\n // get window handle\n const handle = await browser.getWindowHandle()\n\n // create new window\n await browser.newWindow('https://webdriver.io')\n\n // switch back via url match\n await browser.switchWindow('google.com')\n\n // switch back via title match\n await browser.switchWindow('Next-gen browser and mobile automation test framework for Node.js')\n\n // switch back via window handle\n await browser.switchWindow(handle)\n});\n"})})]})}function h(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(w,{...e})}):w(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.