如何使用 WebDriver 自动化 Ace Editor(发送密钥)?

Pri*_*nga 5 ui-automation ace-editor selenium-webdriver

在我的应用程序中,所有查询编辑器都是 Ace 编辑器,我需要使用 WebDriver 输入查询。我试过使用发送键,但它似乎不起作用。有没有其他方法可以将我的输入发送到 Ace 编辑器,从而实现自动化?

下面是我的 HTML 代码

<div class="" ng-show="queryType=='Spark Query'">
    <pre class=" ace_editor ace-xcode">
    <textarea class="ace_text-input" wrap="off" autocorrect="off" autocapitalize="off" spellcheck="false" style="opacity: 0; height: 18px; width: 7px; left: 4px; top: 0px;"/>
    <div class="ace_gutter" style="display: none;">
    <div class="ace_scroller" style="left: 0px; right: 0px; bottom: 0px;">
    <div class="ace_content" style="margin-top: 0px; width: 659px; height: 334px; margin-left: 0px;">
    <div class="ace_layer ace_print-margin-layer">
    <div class="ace_layer ace_marker-layer"/>
    <div class="ace_layer ace_text-layer" style="padding: 0px 4px;">
    <div class="ace_layer ace_marker-layer"/>
    <div class="ace_layer ace_cursor-layer ace_hidden-cursors">
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Sim*_*ier 4

使用编辑器 API 应该比使用 SendKeys 容易得多。例如,下面是一个 C# 控制台应用程序,它启动 ACE 主页并更改当前演示编辑器中的文本:

class Program
{
    static void Main(string[] args)
    {
        ChromeDriver driver = new ChromeDriver();
        driver.Navigate().GoToUrl("http://ace.c9.io/");
        driver.ExecuteScript("editor.setValue('the new text here');");
    }
}
Run Code Online (Sandbox Code Playgroud)

editor是页面中与 ACE 编辑器实例相对应的变量,我刚刚使用了此处详细介绍的第一个 API 示例之一:使用 ACE