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"
}
]
}