2

I have a scenario where I have to use xpath to identify the element . However I want the xpath to be dynamic and the parameter that I pass to xpath should be based on buffer that I stored as part of the test run.

Is it possible to give buffer value in xpath ?

ishaan
  • 49
  • 1
  • 8

2 Answers2

3

Yes, it is possible. You must put the buffer name in quotes. Here how I use it to iterate over Number for div[Number]:

"id('table')/div["{B[Number]}"]"
                 ^-----------^ < note the quotes
Psytho
  • 3,313
  • 2
  • 19
  • 27
0

Have you tried with {B[your_buffer_name]} within your xpath? I never tried using a buffer in a property but that may work.

I would also suggest finding other ways of uniquely identifying your elements. IMHO xpath is rather prone to being unstable. Any change in the page structure will likely break it.

PLB
  • 881
  • 7
  • 20
  • Results in error such as "The XPath-expression 'id('chrome-table')/div[{B[Number]}]/span[1]' could not be evaluated!" This syntax works in inner text or outer text etc but not in xpath which is quite strange. – Psytho Dec 02 '21 at 14:53
  • I see :( and are you absolutely sure that you need am xpath in this case? maybe you can solve it with an anchor or with an "ExplicitName" attribute? – PLB Dec 02 '21 at 18:16
  • 1
    It was not my question but I faced the same problem. I need to go through a column in a table (which is not a table in html-terms) and xpath seems to be the easiest way to do it (just iterate over div[n] in my example above). And tosca cant do it. – Psytho Dec 03 '21 at 12:53
  • sorry, had not seen that you had posted an answer :) good job on finding the solution! – PLB Dec 03 '21 at 17:27