Open link in new tab

Morning (if its your morning)

i appear to be doing something wrong somewhere

to make it a dynamic field, I told it to first storetext of the relevant invoice I want, eg Jacobs Bernadine (31813350(C))

i then did the click like this

{
“Command”: “click”,
“Target”: “//a[contains(@id,“${name}”)]”,
“Value”: “LINK”,
“Description”: “”
},

I did ID instead of Href as it appears to be a part of the id section above, the value is being transferred across the click function and comes out as

Line 9: timeout reached when looking for element ‘//a[contains(@id,“Jacobs Bernadine (31813350(C))”)]’

I tried the same concept looking through the href instead of ID, same result. when using the View term from the href code above, same result.

seems I am not understanding a concept here.

Good morning,

Looks like there is something wrong in your command, have you tried the @href instead of @id ?
you can run this test to understand more how it works, it’s very simple :

{
  "Name": "Go to wikipedia and click english",
  "CreationDate": "2021-9-29",
  "Commands": [
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://www.wikipedia.org/",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "waitForPageToLoad",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//a[contains(@title,\"English\")]",
      "Value": "",
      "Description": ""
    }
  ]
}

concept seems simple enough, and yet it doesnt work on my side.

I copied your code and pasted and adjusted as required, tried the id and href, and both times it could not find it. what I essentially need is the href link in the image below extracted, and then opened in a new window, while dynamically changing what link to extract, and the only thing that changes i can search for is the persons name after the id ext-genXXX

Can you share your web page or any web page with similar problem?

this is accounting software that requires login etc, an account could be made and the demo company used, but I can’t share anything with you specifically.

I tested it on not alwaysright.com and it worked fine

the only difference i can spot is

notalwaysright

a id=“inactivetab” href="/working/">Working</a

xero

a class=“nav” href=“View.aspx?InvoiceID=88617351-56ed-4c14-a30d-34a006d0a75a” id=“ext-gen43”>Bayside Club</a

when i used the formula

“xpath=//a[contains(@href,“working”)]”,

it navigated as it should

use xpath=//a[contains(@href,“bayside”)]

and it times out. if i use ID instead of @href, times out as well. this would suggest the bayside does not form part of the ID or href?

This should work fine. Note that XClick | ... | #ctrlclick on the link opens the page in new tab, but does not switch to the new tab! => For this, you need to use selectWindow | tab=1 afterwards. This command switches to the tab on the right of the currently active tab.

Test:

{
  "Name": "control click",
  "CreationDate": "2021-9-30",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://forum.ui.vision/",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "click // linkText=Categories",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "XClick",
      "Target": "linkText=Categories",
      "Value": "#ctrlclick",
      "Targets": [
        "linkText=Categories",
        "xpath=//*[@id=\"ember36\"]/a",
        "xpath=//li[3]/a",
        "css=#ember36 > a"
      ],
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "TAB=1",
      "Value": "",
      "Description": "tab=1 is the first tab to the right, COUNTED FROM the currently active tab"
    },
    {
      "Command": "click",
      "Target": "linkText=Selenium IDE",
      "Value": "",
      "Description": ""
    }
  ]
}

the functions works and clicks, but it opens it in the current tab instead of a new tab, tested it manually and it worked as expected, so the command is not registering the ctrl click, just the click

{
“Command”: “XClick”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[1]/td[4]/a”,
“Value”: “#ctrlclick”,
“Description”: “”
},

Interesting. As a test:

What if you use an image instead of an Xpath locator, does it work then?

its a dynamic field, the name on the link changes per invoice.

Then you can try with XClickRelative :wink: => The anchor image (green box) in this case would be something next to the link that does not change. And the pink box for the click is at the link.

would not work, due to this being the list. and this is just a example, the name in blue is the link, and could change to whatever customer that invoice is for.

so using an image/relative location, would require replicating it 100 times

Ok, I see. But as a test (with one fixed link): Does XClick | image | #ctrlclick work?

Once we know if that works or not, we can take it from there :wink:

same result as before, it navigated to the right spot, but then opened in the current tab. FYI, The demo account in Xero it exactly the same across all users, so if you used that one as a test ground, it would be exactly the same as the one I see.

same result as before, it navigated to the right spot, but then opened in the current tab.

Good to know. => So it is not a wrong Xpath or Javascript issue.

The demo account in Xero

Do you have a link for that? And once inside the web app, how do I find the right place?

We do have a training doc on Xero which might assist in this regard:

navigate through the left-hand column by clicking, you would be interested in the Xero invoices-invoice navigation and introduction to Xero-Dashboard navigation. company is called demo account, but I think you would be in it already from when you sign up.

Thanks for the test website, that helped!

I am still not sure why it happens. My guess is that somehow this table control “swallows” the CTRL key press. But I found two three (see below for 3rd) good workarounds:

  1. XClick | ... | #ctrlclick works in desktop automation mode! So you can add XDesktopAutomation | true before the XClick. But desktop automation requires the use of image or OCR input for XClick. So since you prefer to use an XPath locator, the second option is better.

  2. Send an XClick | ... | #right click to open the context menu, and then do a mouse down + enter (Xtype | ${KEY_DOWN}${KEY_ENTER} ) to select the first menu entry “Open in new tab”

Both workarounds are shown here:

{
  "Name": "xero",
  "CreationDate": "2021-10-5",
  "Commands": [
    {
      "Command": "XClick",
      "Target": "city_dpi_168.png",
      "Value": "#right",
      "Description": ""
    },
    {
      "Command": "XType",
      "Target": "${KEY_DOWN}${KEY_ENTER}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "XDesktopAutomation",
      "Target": "true",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "XClick",
      "Target": "city_dpi_168.png",
      "Value": "#ctrlclick",
      "Description": ""
    }
  ]
}

Also, I found that the store attribute solution as suggested by @erdomay7 works as well, once you find the right xpath.

In our case we need the one with the /a at the end. It contains the href attribute:

image

So this works:

  1. extract URL with “store attribute @href
  2. Split string to get ID
  3. Combine the “View.aspx” base URL with ID
  4. Open new tab with selectWindow | Tab=Open

See here:

Macro:

{
  "Name": "storeattribute",
  "CreationDate": "2021-10-5",
  "Commands": [
    {
      "Command": "storeAttribute",
      "Target": "xpath=//tr[4]/td[4]/a@href",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${a}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${a}.split(\"=\")[1].trim();",
      "Value": "b",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${b}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "TAB=OPEN",
      "Value": "https://go.xero.com/AccountsReceivable/View.aspx?InvoiceID=${b}",
      "Description": ""
    }
  ]
}

busy testing this one, works best with the constantly changing variable, just having issues getting to click on the right element, seems to see the column headers ( to, due date, date etc) as the first value and stores that even though the element bayside club is the first element, but that is my problem to look into.

ok one odd thing, the code below:

Blockquote
{
“Command”: “open”,
“Target”: “https://go.xero.com/AccountsReceivable/Search.aspx”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “linkText=Due Date”,
“Value”: “”,
“Targets”: [
“linkText=Due Date”,
“xpath=//[@id=“ext-gen41”]/thead/tr/td[6]/a",
“xpath=//td[6]/a”,
“css=#ext-gen41 > thead > tr > td.selected > a”
],
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “1000”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “linkText=Due”,
“Value”: “”,
“Targets”: [
“linkText=Due”,
"xpath=//
[@id=“ext-gen41”]/thead/tr/td[9]/a”,
“xpath=//td[9]/a”,
“css=#ext-gen41 > thead > tr > td:nth-child(9) > a”
],
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “1000”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “type”,
“Target”: “id=sb_txtReference”,
“Value”: “CN”,
“Targets”: [
“id=sb_txtReference”,
“name=invoiceReference”,
“xpath=//[@id=“sb_txtReference”]",
“xpath=//input[@id=‘sb_txtReference’]”,
“xpath=//div/input”,
“css=#sb_txtReference”
],
“Description”: “”
},
{
“Command”: “click”,
“Target”: “linkText=Search”,
“Value”: “”,
“Targets”: [
“linkText=Search”,
“id=sbSubmit_”,
"xpath=//
[@id=“sbSubmit_”]”,
“xpath=//a[@id=‘sbSubmit_’]”,
“xpath=//a[2]”,
“css=#sbSubmit_”
],
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “2000”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “times”,
“Target”: “10”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “store”,
“Target”: “2”,
“Value”: “i”,
“Description”: “”
},
{
“Command”: “while_v2”,
“Target”: “${i}<200”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number (${i}) +1;”,
“Value”: “Link”,
“Description”: “reconcile”
},
{
“Command”: “storeAttribute”,
“Target”: “xpath=//tr[${i}]/td[4]/a@href”,
“Value”: “a”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “${a}”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return ${a}.split(”=")[1].trim();",
“Value”: “b”,
“Description”: “”
},
{
“Command”: “selectWindow”,
“Target”: “TAB=OPEN”,
“Value”: “https://go.xero.com/AccountsReceivable/ViewCreditNote.aspx?creditNoteID=${b}”,
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “2000”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “assertText”,
“Target”: “xpath=//[@id=“ext-gen25”]/div[2]/div[5]/div[3]/div[4]/label",
“Value”: “Total Credit”,
“Description”: “”
},
{
“Command”: “if_v2”,
“Target”: “${!LastCommandOk} == true”,
“Value”: “if total credit”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “id=ext-gen32”,
“Value”: “”,
“Targets”: [
“id=ext-gen32”,
"xpath=//
[@id=“ext-gen32”]”,
“xpath=//div[@id=‘ext-gen32’]”,
“xpath=//dt/div”,
“css=#ext-gen32”
],
“Description”: “”
},
{
“Command”: “assertText”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/div[4]/div[3]/dl/dd/ul/li[1]/a”,
“Value”: “Allocate Credit”,
“Description”: “”
},
{
“Command”: “if_v2”,
“Target”: “${!LastCommandOk} == true”,
“Value”: “if apply is present”,
“Description”: “”
},
{
“Command”: “clickAndWait”,
“Target”: “//[@id=“ext-gen28”]/ul/li[1]/a",
“Value”: “”,
“Description”: “”
},
{
“Command”: “times”,
“Target”: “20”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “verifyElementPresent”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[${!times}]/td[5]”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “if_v2”,
“Target”: “${!LastCommandOk} == true”,
“Value”: “if present”,
“Description”: “”
},
{
“Command”: “storeText”,
“Target”: “id=AmountDue”,
“Value”: “remaining_credit”,
“Description”: “”
},
{
“Command”: “storeText”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[${!times}]/td[5]”,
“Value”: “amount_due”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “var a = ${remaining_credit}; return a.replace(’,’, ‘’);”,
“Value”: “remaining_credit”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “var a = ${amount_due}; return a.replace(’,’, ‘’);”,
“Value”: “amount_due”,
“Description”: “”
},
{
“Command”: “if_v2”,
“Target”: “parseFloat (${remaining_credit}) - parseFloat (${amount_due}) >= 0”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “type”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[${!times}]/td[6]/div/span/input”,
“Value”: “${amount_due}”,
“Description”: “”
},
{
“Command”: “sendKeys”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[${!times}]/td[5]”,
“Value”: “${amount_due}”,
“Description”: “”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “if_v2”,
“Target”: “parseFloat (${amount_due}) - parseFloat (${remaining_credit}) >= 0”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “type”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[${!times}]/td[6]/div/span/input”,
“Value”: “${remaining_credit}”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/table/tbody/tr[${!times}]/td[5]”,
“Value”: “${amount_due}”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “gotoLabel”,
“Target”: “complete”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “label”,
“Target”: “complete”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: "//
[@id=“ext-gen14”]”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “1000”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “selectWindow”,
“Target”: “TAB=CLOSE”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “clickAndWait”,
“Target”: “/html/body/div[2]/form/div/div[1]/div[2]/div[6]/ul/li[6]/a”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “gotoLabel”,
“Target”: " invoices",
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}
]
}

specifically the part from the while to select window, if i put the store as 1, the store attribute links to the column headers and returns that value, if I put the store as 2, it then pulls the 2nd credit note on the list. is there a reason why it would skip the first credit note?

Hi All

i take it there is no reason for this to occur?