2

Iam currently trying to demonstrate a copy paste action using Protracter. I need to copy a url and open a new tab and paste and navigate to it. Currently I'am able to copy and open a new tab and paste the URL in Address Bar but I'am unable to navigate to the URL in Address Bar.Please find the code below.

 browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "t")).perform();
  browser.sleep(2000);
  browser.getAllWindowHandles().then(function(handles){
  browser.switchTo().window(handles[1]).then(function(){
        //do your stuff on the pop up window
  browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'v')).perform();
  browser.actions().sendKeys(protractor.Key.chord(protractor.Key.ENTER)).perform();
albert
  • 369
  • 2
  • 5
  • 16

1 Answers1

2

The browser's address bar is out of Protractor/WebDriverJS/Selenium's scope, you cannot control it. But, what you can do is to issue browser.get() once you've switched to the newly opened window:

browser.switchTo().window(handles[1]).then(function() {
  browser.get(url);
});

Now, if you don't know the url and it's being dynamically retrieved and "sits" in the clipboard, what you can do is to create an input element dynamically, paste the contents of the clipboard into the element, and retrieve it via getAttribute("value"), see the actual sample implementation here:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195