Store value from the right cell of the curent position

Hello,

I have a web page on which there is a table dynamically generated. My task is to get a certain value from a particular cell. The cell position is not fixed, but the value is always in the cell right next to a cell which contains a predefined text.

I have managed to find the text in the page, my problem is that I do not know how to use the cell position and store it into a variable.

Or maybe thee is another way to get the value placed in the cell next to the one containing the reference text?

For example, if the reference text is at the position: xpath=/html/body/form/table[1]/tbody/tr[1]/td[4], I would like to get the value placed here: xpath=/html/body/form/table[1]/tbody/tr[1]/td[5]

Thank you!

1 Like

but the value is always in the cell right next to a cell which contains a predefined text.

The general procedure is to make a loop like this:

  • storeText (locator of cell with predefined text) => extract text in the anchor cell.
  • check if extracted text meets condition e. g. is a certain name
  • If so, then we know we are in a correct row! => Now get the value of the right cell (in your case) or check the box (in the example below) in the current row:

Note that we loop over all lines of the table by replacing parts of the locator with a variable (to find the value to replace, click on several rows during recording, then you see what values changes => replace it with variable, in the example it is ${n}). Here it is like this:

  • xpath=//*[@id="tasks-wizard"]/div[4]/div/div/table/tbody/tr[${n}]/td[2]
  • and the checkbox has: xpath=//*[@id="tasks-wizard"]/div[4]/div/div/table/tbody/tr[${n}]/td[1]/label/input

The code for the macro used here is:

    {
      "Name": "CheckNames",
      "CreationDate": "2019-6-24",
      "Commands": [
        {
          "Command": "open ",
          "Target": "https://www. (some CRM system).com/tasks",
          "Value": ""
        },
        {
          "Command": "store",
          "Target": "1",
          "Value": "n"
        },
        {
          "Command": "store",
          "Target": "fast",
          "Value": "!replayspeed"
        },
        {
          "Command": "store",
          "Target": "true",
          "Value": "!statusOK"
        },
        {
          "Command": "verifyElementPresent",
          "Target": "xpath=//*[@id=\"tasks-wizard\"]/div[4]/div/div/table/tbody/tr[${n}]/td[2]",
          "Value": ""
        },
        {
          "Command": "while_v2",
          "Target": "${!statusOK} == \"true\"",
          "Value": ""
        },
        {
          "Command": "storeText",
          "Target": "xpath=//*[@id=\"tasks-wizard\"]/div[4]/div/div/table/tbody/tr[${n}]/td[2]",
          "Value": "name"
        },
        {
          "Command": "echo",
          "Target": "Extracted: ${n} => ${name}",
          "Value": "blue"
        },
        {
          "Command": "click",
          "Target": "xpath=//*[@id=\"tasks-wizard\"]/div[4]/div/div/table/tbody/tr[${n}]/td[1]/label/input",
          "Value": "on"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return Number(${n})+1",
          "Value": "n"
        },
        {
          "Command": "store",
          "Target": "true",
          "Value": "!statusOK"
        },
        {
          "Command": "comment",
          "Target": "Check that next element still exists",
          "Value": ""
        },
        {
          "Command": "verifyElementPresent",
          "Target": "xpath=//*[@id=\"tasks-wizard\"]/div[4]/div/div/table/tbody/tr[${n}]/td[2]",
          "Value": ""
        },
        {
          "Command": "end",
          "Target": "",
          "Value": ""
        },
        {
          "Command": "echo",
          "Target": "done",
          "Value": "green"
        }
      ]
    }
1 Like