Use a variable list in an xpath

I have a list of reports which I would like to download from a website

Report list
report A Export / Edit / Delete
report B Export / Edit / Delete
report XYZ Export / Edit / Delete
report 2 Export / Edit / Delete
report D Export / Edit / Delete

I do not want to have to export all reports every time. My idea is to create select the reports I want to export from an xls file and create from there a list variable (called report_list).
Each export xpath reads indeed as follow (using report A as an example)
//span[contains(@class, ‘export_name’) and text()=‘report A’]/following-sibling::a[@class="“export_reexport”"]
But when I use a for each loop and the report_list variable in the xpath as per below, it does not work
//span[contains(@class, ‘export_name’) and text()=’${report_list}’]/following-sibling::a[@class="“export_reexport”"]

Is it possible to use a variable list in Xpath and if not, what would you recommend as an alternative approach in such case?

Hi @Isabelle in the Xpath, you should use the String variable, not the list variable.
In the example below, you will need to use ${element}, i.e. //span[contains(@class, ‘export_name’) and text()=’${element}’]/following-sibling::a[@class="“export_reexport”"]

@ashapkina, I proceeded as indicated, but I am afraid it is still not working.
Here is my list as it appears in the execution-result.log
export_report LIST “[UK FB Display WWC, report XYZ]”

and here is how I wrote my Xpath

Do you see anything wrong with this?

Here is the message I get from the execution error board

When I proceed without the loop and replace ‘${element}’ by ‘UK FB Display WWC’, it works fine.
(The only thing I bring in is the ‘For each loop’, designed as such:

I have tried also to add time by the way, and it does not work. Any idea what I could be doing wrong here?

1 Like

@Isabelle I cannot think of a reason for this right now. Is it possible to share the URL to test it?

Hello Isabelle,

It seems to me that the problem is that your xpath has an incorrect format. Could you please try the following?
//span[contains(@class,‘export_name’) and text() = ‘${element}’]/following-sibling::a[@class=‘export_reexport’]

(you have in the error : The String […] is not a valid XPath expression line 10)

1 Like