How can I record ""right-click"" new-tab?


#1

How can I record ““right-click”” new-tab?


#2

You can not record manually opening a new tab via right-click, but (after recording) you can insert this command, which does the same:

selectWindow | TAB=OPEN | https://newwebsiteURL.com

See also https://a9t9.com/kantu/docs/selenium-ide/selectwindow


#3

Hi Timo,

I am actually looking at getting the program to open a link in a new window – meaning a link a web page, and then the program must continue running on the same (old) page, ignoring the new tab that has been opened.

E.g.


#4

How about extracting the URL with storeAttribute | …@href and then open this URL in a new tab, and then go back to tab 1? This macro works for me:

{
  "CreationDate": "2018-10-17",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://a9t9.com/kantu/docs#!errorignore",
      "Value": ""
    },
    {
      "Command": "storeAttribute",
      "Target": "link=flow control@href",
      "Value": "yyy"
    },
    {
      "Command": "selectWindow",
      "Target": "tab=open",
      "Value": "https://a9t9.com/${yyy}"
    },
    {
      "Command": "comment",
      "Target": "go back to left tab",
      "Value": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=0",
      "Value": ""
    }
  ]
}


#5

I wish also I could use the ‘click’ function, and specify that the result opens in a new window or tab. I know that the ‘selectwindow’ allows this, but on a website I’d like to scrape, this doesn’t work. More specificaly, on https://www.cecb.ch/Pages/GEAK/Contact/ExpertSearchPage.aspx, how can you open the link under the ‘look at details’ icon into a new tab?
Thanks otherwise for a great software,


#6

Looks like it does require referrer.
I’m not sure if Kantu or Selenium IDE can work with referrer but I have a solution for you if somebody does not come up with a better idea.

Look at a piece bellow. First command’s target is a link you want to open. You can pick it with a button, but pay attention at the end. It’s /a@href. Stores your link. I think you do it dynamically in the script and can figure it out but I just wanted to point it out.
Works for me.

{
  "Command": "storeAttribute",
  "Target": "//*[@id=\"_cphMasterContent__cphPageContent__searchControl__searchResults__searchResultsGridView_DXDataRow5\"]/td[9]/a@href",
  "Value": "path"
},
{
  "Command": "selectWindow",
  "Target": "TAB=OPEN",
  "Value": "https://www.cecb.ch/Pages/GEAK/Contact/ExpertSearchPage.aspx"
},
{
  "Command": "open",
  "Target": "https://www.cecb.ch/${path}",
  "Value": ""
},
{
  "Command": "comment",
  "Target": "Do whatever you need to.",
  "Value": ""
},
{
  "Command": "selectWindow",
  "Target": "TAB=0",
  "Value": "https://www.cecb.ch/Pages/GEAK/Contact/ExpertSearchPage.aspx"
},
{
  "Command": "selectWindow",
  "Target": "TAB=CLOSEALLOTHER",
  "Value": "https://www.cecb.ch/Pages/GEAK/Contact/ExpertSearchPage.aspx"
}

UPD. I will read comments next time before posting. (( This is exactly what Timo suggested. I just wrote it and looked up. Haha. I kinda stole his idea.


#7

Just to add another solution: One can also use XClick | locator | #right to right-click and open the context menu, and then select “Open in new tab” from the context menu with the keystrokes “Down, Enter” via XType.

{
  "CreationDate": "2018-10-29",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.cecb.ch/Pages/GEAK/Contact/ExpertSearchPage.aspx?ln=fr",
      "Value": ""
    },
    {
      "Command": "XClick",
      "Target": "//*[@id=\"_cphMasterContent__cphPageContent__searchControl__searchResults__searchResultsGridView_DXDataRow1\"]/td[9]/a/img",
      "Value": "#right"
    },
    {
      "Command": "XType",
      "Target": "${KEY_DOWN}${KEY_ENTER}",
      "Value": ""
    },
    {
      "Command": "pause",
      "Target": "2000",
      "Value": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=1",
      "Value": ""
    }
  ]
}

#8

With XClick you can click with #middle button right away and it will open in a new tab. No XType needed.
But the downside of X… it will bring the browser to front. Not very convenient all the time.