Search code examples
protractor

Protractor right click open in a new tab wrong menu proposed


I have a problem when I do the test of a right click with Protractor.

The element where I right click is a link ''

However when the test is run in chromeDriver the tab that appears is not a tab that offers the possibility of opening in a new tab.

enter image description here

It should rather be this

enter image description here

In protractor I use the following code:

 let link = element(by.css('.ag-body-container div[colid="test"] a'));
      await browser.actions().mouseMove(link).perform();
      await browser.actions().click(protractor.Button.RIGHT).perform();
      await browser.actions().mouseMove(link).keyDown(protractor.Key.CONTROL).click().perform();
      await browser.actions().mouseMove(link).keyDown(protractor.Key.CONTROL).click().keyUp(protractor.Key.CONTROL).perform();

If you have a solution to this problem I know that this problem has already been posed but without solution provided

No right click - open in new tab


Solution

  • I assume you have a Single Page App or some similar setup and you are executing the nav clicks with javascript, but you want them to also behave like links.

    If so, wrap your navigation item in an a tag linking to the link, and prevent executing the link on left click with js

    function navClick(event){
      alert("click action");
      return false;
    }
    <a href="//google.com" onclick="return navClick()"><button>Link</button></a>

    Hope this helps!