問題描述
如何使用量角器復制特定文本?
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的剪貼板中的文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!