如何使用 WebDriver 自动化 Ace Editor(发送密钥)? [英] How to automate the Ace Editor (send keys) using WebDriver?

查看:27
本文介绍了如何使用 WebDriver 自动化 Ace Editor(发送密钥)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

下面是我的 HTML 代码

<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">

解决方案

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

class 程序{静态无效主(字符串 [] args){ChromeDriver 驱动程序 = new ChromeDriver();driver.Navigate().GoToUrl("http://ace.c9.io/");driver.ExecuteScript("editor.setValue('这里的新文本');");}}

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

In my application all the query editors are Ace editor and I need to type in queries using WebDriver. I have tried using send keys but it doesn't seem to work. Is there any other way I can send my input to Ace editor and thus automate?

Below is my HTML code

<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>

解决方案

It should be much easier to use the editor API than SendKeys. For example, here is a C# console app that lauches ACE home page and change the text in the current demo editor:

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');");
    }
}

editor is the variable in the page that corresponds to the ACE editor instance, and I've just used one of the first API samples detailed here : Working with ACE

这篇关于如何使用 WebDriver 自动化 Ace Editor(发送密钥)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆