有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javascript如何使用selenium web驱动程序在代码镜像中输入值?

我目前面临一个与代码镜像中的输入值相关的问题(仅供参考:输入是html代码)

非常感谢任何帮助

这就是我目前正在做的(但我需要在每行代码镜像中插入值)

JavascriptExecutor js = (JavascriptExecutor)driver;
Js.executeScript("arguments[0].CodeMirror.setValue(\"" + value + "\");", driver.findElementBy(By.id("id")));

enter image description here

页面源代码为:

<div class="CodeMirror cm-s-default">
<div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 5px; left: 35px;">
<textarea wrap="off" style="position: absolute; padding: 0px; width: 1px; height: 1em; outline: medium none;" autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"></textarea>
</div>
<div class="CodeMirror-vscrollbar" cm-not-content="true" style="min-width: 18px;">
<div style="min-width: 1px; height: 0px;"></div>
</div>
<div class="CodeMirror-hscrollbar" cm-not-content="true" style="min-height: 18px;">
<div style="height: 100%; min-height: 1px; width: 0px;"></div>
</div>
<div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div>
<div class="CodeMirror-gutter-filler" cm-not-content="true"></div>
<div class="CodeMirror-scroll" tabindex="-1" draggable="true">
<div class="CodeMirror-sizer" style="margin-left: 30px; margin-bottom: 0px; border-right-width: 30px; min-height: 31px; min-width: 7px; padding-right: 0px; padding-bottom: 0px;">
<div style="position: relative; top: 0px;">
<div class="CodeMirror-lines">
<div style="position: relative; outline: medium none;">
<div class="CodeMirror-measure">
<span>
<span>​</span>
x
</span>
</div>
<div class="CodeMirror-measure"></div>
<div style="position: relative; z-index: 1;"></div>
<div class="CodeMirror-cursors">
<div class="CodeMirror-cursor" style="left: 4px; top: 0px; height: 22.85px;"> </div>
</div>
<div class="CodeMirror-code">
<div style="position: relative;">
<div class="CodeMirror-gutter-wrapper" style="left: -30px;">
<div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">1</div>
</div>
<pre class=" CodeMirror-line ">
<span>
<span cm-text="">​</span>
</span>
</pre>
</div>
</div>
</div>
</div>
</div>
</div>

所以问题是如何在代码镜像的不同行中输入值


共 (2) 个答案

  1. # 1 楼答案

    你的问题不是很清楚,但我认为你想要的是在不同的行中插入文本,而不是在一行中插入所有文本。如果是这种情况,则需要在字符串中希望回车的位置插入\n

    一个示例字符串是string sample = "<html>\n <test>\n</html>",它应该生成

    <html>
      <test>
    </html>
    
  2. # 2 楼答案

    通过将输入值更改为此,我可以使用换行符输入代码镜像。。 <html>\\r<test>\\r</html>