paste url from clipbaord to browser address bar

 ̄綄美尐妖づ 提交于 2020-01-06 08:44:07

问题


I need to copy url and paste it to browser address bar. Unfortunately when I copy url there is no data attribute from where I can getText and paste.

I used actions class as below to paste the url. But doesn't seem to work.

HMTL code:

  <li class="copyLink">
  <span class="link">Copy link</span>
  <input class="input" readonly="">
 </li> 

await browser.executeScript("window.open(arguments[0], '_blank')"); // opens new tab await browser.actions().keyUp(protractor.Key.CONTROL).perform();//to paste in the address bar await browser.sleep(1000);

Any suggestions on whats wrong with the code ?

Thanks


回答1:


UPDATED CODE AGAIN:

You were very close in your initial attempt. Using the sendKeys method you can send the current copied code in the clipboard to the current selected element using

await browser.actions().sendKeys(protractor.Key.CONTROL, 'v').perform();

You were missing the 'v' which, as I'm sure your aware, is the button you need on the keyboard after the control button is pressed.

This is where you can read more about sending specific key presses with Protractor

Latest Update:

If you address bar is not focused then the above approach will not work and I have not found a way to manually focus the address bar at this time. Another approach you could try is to use an npm package like clipboardy. This will allow you to copy to clipboard contents to a variable and then use a browser.get() to reach the required URL.

Install clipboardy package

npm i clipboardy

In your test

const clipboardy = require('clipboardy');

//create variable with value from clipboard
let urlFromClipboard= await clipboardy.read();

await browser.get(urlFromClipboard);


来源:https://stackoverflow.com/questions/54460908/paste-url-from-clipbaord-to-browser-address-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!