文字与量角器JS剪贴板 [英] Text in clipboard with protractor 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 aCTRL/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 handleCTRL
/COMMAND
keys:这篇关于文字与量角器JS剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!