Xpath is not working when binded with a variable

Best practices, code snippets for common functionality, examples, and guidelines.
theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Xpath is not working when binded with a variable

Post by theraviz » Wed Apr 22, 2020 10:40 am

HI,

I have to identify a table cell based on the comparison with other cells in the same row. I created an xpath for that and it works well for all other condition except for one cell where I am checking whether it is greater than a particular number (_population in the below xpath)

/table//td/table[2]//td[@innertext~$_country]/../td[2]/following-sibling::td/img[@src~$_flag]/../following-sibling::td[@innertext>$_population]/preceding-sibling::td[2]//a

Since I need to get all the values based on the above xpath I am passing this repo item to a function where I am using IList to get all values.

Now the problem that xpath is not taking the _population value which is passing as parameter. I have defined the same in global Parameters and binded this to _population. Except this value all other values are working fine.

When I removed the binded variable and put a static number in the xpath, now its properly Identifying the contrl.

/table//td/table[2]//td[@innertext~$_country]/../td[2]/following-sibling::td/img[@src~$_flag]/../following-sibling::td[@innertext>1000]/preceding-sibling::td[2]//a

How to solve this?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6190
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Xpath is not working when binded with a variable

Post by odklizec » Wed Apr 22, 2020 10:58 am

Hi,

Please post a Ranorex snapshot (not screenshot) of the problematic element and a sample solution simulating your problem. It's impossible to tell what;s wrong without seeing the UI (at very least snapshot) and structure of your solution with binded variables and repo. Thanks.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Re: Xpath is not working when binded with a variable

Post by theraviz » Wed Apr 22, 2020 11:26 am

odklizec wrote:
Wed Apr 22, 2020 10:58 am
Hi,

Please post a Ranorex snapshot (not screenshot) of the problematic element and a sample solution simulating your problem. It's impossible to tell what;s wrong without seeing the UI (at very least snapshot) and structure of your solution with binded variables and repo. Thanks.
Attached.
Last edited by theraviz on Wed Apr 22, 2020 4:04 pm, edited 1 time in total.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6190
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Xpath is not working when binded with a variable

Post by odklizec » Wed Apr 22, 2020 12:15 pm

Hi,

I think I now understand. The problem is, that the xpath attributes are ALWAYS strings so they cannot be compared as numbers. In fact, '>' in xpath expression means "start with"! To evaluate the innertext as a number, you must adapt the xpath like this:
/table//td/table[2]//td[@innertext~$_country]/../td[2]/following-sibling::td/img[@src~$_flag]/../following-sibling::td[text()>$_population]/preceding-sibling::td[2]//a
Last edited by odklizec on Wed Apr 22, 2020 1:17 pm, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Re: Xpath is not working when binded with a variable

Post by theraviz » Wed Apr 22, 2020 1:06 pm

Thank you. Its resolved :)