-
Notifications
You must be signed in to change notification settings - Fork 73
WebView
github-actions[bot] edited this page May 16, 2024
·
5 revisions
import { EditorView, WebView } from 'vscode-extension-tester';
...
// using EditorView
const webview = new EditorView().openEditor('webview-title');
// using the constructor assuming the editor is opened
const webview1 = new WebView();
In order to access the elements inside the web view frame, it is necessary to switch webdriver context into the frame. Analogically, to stop working with the web view, switching back is necessary.
// to switch inside the web view frame, with optional customizable timeout
await webview.switchToFrame(5_000);
// to switch back to the default window
await webview.switchBack();
Make sure when searching for and manipulating with elements inside (or outside) the web view that you have switched webdriver to the appropriate context. Also, be aware that referencing an element from the default window while switched to the web view (and vice versa) will throw a StaleElementReference
error.
// first, switch inside the web view
await webview.switchToFrame();
// look for desired elements
const element = await webview.findWebElement(<locator>);
const elements = await webview.findWebElements(<locator>);
...
// after all web view manipulation is done, switch back to the default window
await webview.switchBack();