Updating the editor contents in v6 from Selenium

In CodeMirror 5, it is possible for a Selenium test to extract an property called CodeMirror on the DOM Element styled with class CodeMirror, and call setValue on that property to change the editor text. But this does not work with CodeMirror 6.

The hierarchy of DIVs is very different in CodeMirror 6, with style classes such as cm-editor, cm-theme and cm-content, and attempting to pick off the CodeMirror property off the elements with these classes returned undefined.

Is there an equivalent “way in” to modify the editor contents in CodeMirror 6?

See EditorView.findFromDOM.

Thanks that was a big help, but I could not use that verbatim, as Selenium has limited access to the HTMLElements, in the form of its own “WebElements”.

I mimicked the internals of findFromDOM: I used Selenium calls to locate the WebElement with class cm-content, and ran the same sort of logic that would be used in CodeMirror 5 inside a separate script, passing in the WebElement which would be converted to an HTMLElement. This works but I am concerned this is a little dependent on the internal structure of CodeMirror. I do not think it is possible to import the EditorView type inside one of these ad hoc scripts.

webDriver.executeScript(
      'const cm = arguments[0].cmView.rootView.view; cm.dispatch({ changes: {from: 0, to: cm.state.doc.length, insert: "' +
        textIWantInserted +
        '"}});',
      webElementExtractedFromDOMWithClassCmContent
    );