文字与量角器JS剪贴板 [英] Text in clipboard with protractor js

查看:108
本文介绍了文字与量角器JS剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以复制特定的文本用量角器?

我想加载一个文本使用此命令后粘贴:

 返回browser.actions()的SendKeys(Keys.CONTROL,'V')执行()。

示例:

加载我的文字测试后使用此命令,粘贴测试

我想提出的文本在我的剪贴板


解决方案

  

我可以直接把一个值在我的NG-模式,而不是使用的SendKeys?


是的,你可以直接通过的模式价值.prototype.evaluate相对=nofollow> 评估()

  VAR榆树=元素(by.model(mymodel.field));
elm.evaluate(mymodel.field ='测试';);


把文本到剪贴板

我们的想法是利用现有的或动态创建一个输入元素,你会送文本,选择输入的所有文本,并用它复制 CTRL / COMMAND + C 快捷方式。

示例:

  VAR textToBeCopied =我的文字;//创建一个新的input元素
browser.executeScript(函数(){
    VAR EL =使用document.createElement('输入');
    el.setAttribute('身份证','customInput');    document.getElementsByTagName('身体')[0] .appendChild(EL);
});//输入值设定为所需的文本
VAR newInput = $(#customInput);
newInput.sendKeys(textToBeCopied);//选取所有及复印件
newInput.sendKeys(protractor.Key.chord(browser.controlKey,一个));
newInput.sendKeys(protractor.Key.chord(browser.controlKey,C));

其中, browser.controlKey 是一个跨平台的方式来处理 CTRL / 命令键:

How can I copy a specific text with protractor ?

I would like to load a text to paste after with this command :

return browser.actions().sendKeys(Keys.CONTROL, 'v').perform();

Sample :

Load my text "test" and after with this command, paste "test"

I would like put a text in my clipboard

解决方案

can I put a value directly in my ng-model, not use sendKeys ?

Yes, you can directly set the model value via .evaluate():

var elm = element(by.model("mymodel.field"));
elm.evaluate("mymodel.field = 'test';");


Putting a text into clipboard

The idea is to use an existing or dynamically create an input element where you would send the text to, select all the text in the input and copy it with a CTRL/COMMAND + C shortcut.

Sample:

var textToBeCopied = "my text";

// creating a new input element
browser.executeScript(function () {
    var el = document.createElement('input');
    el.setAttribute('id', 'customInput'); 

    document.getElementsByTagName('body')[0].appendChild(el);
});

// set the input value to a desired text
var newInput = $("#customInput");
newInput.sendKeys(textToBeCopied);

// select all and copy
newInput.sendKeys(protractor.Key.chord(browser.controlKey, "a"));
newInput.sendKeys(protractor.Key.chord(browser.controlKey, "c"));

where browser.controlKey is a cross-platform way to handle CTRL/COMMAND keys:

这篇关于文字与量角器JS剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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