Variable in input (xpath). how to setup?


I need to calculate similar objects on the random chart
I try to use variable in xpath to define a random chart. I can’t understand how to work with variable in input in this case. Please help me with your advice.

Thank you in advance for your help!

You have the attribute, “name”, as a method instead of an attribute, so put an “at” sign in front of it and remove the parameters from back of it. Also, you should have the double quotes as your starting ones and have single quote on anything that needs it within the quotes. How about try:

List<WebElement> list3 = driver.findElements(By.xpath("//*[@name='as-split-area' and @id='container${index2}']//*[@name='g' and contains(@class, 'recharts-reference-line')]"))
1 Like

@grylion54 Thank you for your answer.
I modified the xpath. But the problem is to define index in this step. Usually I added the param index to variables of an object (screen below) but for input it is impossible.

I configured the test to check the xpath without index.
Objects are calculated for xpaths without variable. How to define the variable that is in input?

You have this line

Here you have a mistake.

"//*[name()='as-split-area' and @id='container\${index1}']//*[name()='g' and contains(@class, 'recharts-reference-line')]"
                                              ^ this back-slash sign should not be there

@kazurayam Thank you. But {index1} is still does not recognized as variable.

Sorry, I made a careless mistake.

Wrong: “this dollar sign should not be there”

Right: “this back-slash sign should not be there”


@kazurayam Thank you! It works!

1 Like