无法使用量角器获取摩纳哥编辑器中的文本

编程入门 行业动态 更新时间:2024-10-26 16:27:44
本文介绍了无法使用量角器获取摩纳哥编辑器中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 protractor-cucumber 框架为 Monaco-editor 编写 BDD 测试.不久前,我发现了 Monaco API 以及如何以编程方式在编辑器中设置值.但这一次,我无法使用量角器在 monaco 编辑器中获取文本.这是我的代码示例:

I am writing BDD tests for Monaco-editor using the protractor-cucumber framework. A while ago, I found about Monaco API's and how to set the value inside the editor programmatically. But this time, I am unable to get the text inside monaco editor using protractor. Here's a sample of my code:

browser.ignoreSynchronization = true; let driver = browser.driver; // iframe ids let iframeID = 'editorFrame'; let editorSpanXpath = '//div[@id="editorContainer"]//div[contains(@class, "monaco- editor")]//div[contains(@class, "editor-scrollable")]' // switching to the iFrame to perform tasks inside it browser.switchTo().frame(iframeID); // clicking on a div inside the editor to ascertain that // the browser knows where to run the script driver.findElement(by.xpath(editorSpanXPath)).click(); browser.executeScript('this.monaco.editor.getModels()[0].getValue()').then(function(editorText){ let replaceString = 'abracadbra' + editorText browser.executeScript('this.monaco.editor.getModels()[0].setValue("' + replaceString + '")'); } );

这里的问题是 'editorText' 的值一直为空.在运行我的 BDD 测试时,编辑器中的值被替换为 'abracadabranull'

The problem here is that the value of 'editorText' keeps coming up null. On running my BDD tests, the value inside the editor is replaced by 'abracadabranull'

编辑器使用一些默认文本进行初始化.由于setValue"函数正在运行,我认为浏览器驱动程序在获取加载编辑器的 iFrame 方面没有问题.

The editor is initialized with some default text. And since the 'setValue' function is working, I figure that the browser driver has no trouble in getting the iFrame where the editor gets loaded.

任何帮助将不胜感激.

推荐答案

最后,是一个简单的 return 语句挽救了这一天:

In the end, it was a simple return statement that saved the day:

browser.ignoreSynchronization = true; let driver = browser.driver; // iframe ids let iframeID = 'editorFrame'; let editorSpanXpath = '//div[@id="editorContainer"]//div[contains(@class, "monaco- editor")]//div[contains(@class, "editor-scrollable")]' // switching to the iFrame to perform tasks inside it browser.switchTo().frame(iframeID); // clicking on a div inside the editor to ascertain that // the browser knows where to run the script driver.findElement(by.xpath(editorSpanXPath)).click(); browser.executeScript('return this.monaco.editor.getModels()[0].getValue()').then(function(editorText){ let replaceString = 'abracadbra' + editorText browser.executeScript(' return this.monaco.editor.getModels()[0].setValue("' + replaceString + '")'); } );

非常感谢这个 为我指明正确方向的答案.

Many thanks to this answer for pointing me in the right direction.

更多推荐

无法使用量角器获取摩纳哥编辑器中的文本

本文发布于:2023-11-23 03:35:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:摩纳哥   量角器   器中   文本   编辑

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!