带有量角器js的剪贴板中的文本 [英] Text in clipboard with protractor js

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

问题描述

如何使用量角器复制特定文本?

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();

示例:

加载我的文本test",然后使用此命令粘贴test"

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

我想在我的剪贴板中放一个文本

I would like put a text in my clipboard

推荐答案

我可以直接在我的 ng-model 中输入一个值,而不是使用 sendKeys 吗?

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

是的,您可以通过 model 值="nofollow noreferrer">.evaluate():

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

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


将文本放入剪贴板

这个想法是使用现有的或动态创建一个 input 元素,您可以将文本发送到该元素,选择输入中的所有文本并使用 CTRL/COMMAND + 复制它C 快捷方式.


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.

示例:

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

其中 browser.controlKey 是处理 CTRL/COMMAND 键的跨平台方式:

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

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

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