Variables in Repository not getting right value
Variables in Repository not getting right value
I am using variables in the repository that will 'randomly' select an option on the web page. I have this in the repository li[2]/span[$Question]/?/?/span , but it is replaced by this li[2]/span['1']/?/?/span during runtime. The original definition was listed as li[2]/span[1]/?/?/span. How do I get it to replace the variable without single quotes?
Thanks,
Zoë (aka zoework)
Zoë (aka zoework)
Re: Variables in Repository not getting right value
The problem is that Ranorex treats all variables in the XPath of a repo item as a single-quoted string, so it will always put the ticks around the value to make sure that the final XPath is correctly formatted. XPath requires all strings to have ticks.
The way to handle this type of thing is to add the attribute to the XPath, in your case the attribute would be "[@childIndex=$Question]". This would then be evaluated by XPath at runtime as "[@childIndex='1']".
I would also suggest that you make sure to have a well-defined parent for this item. Instead of 'li[2]', try to find an attribute of the li tag that is more consistent.
My final suggestion would be to find something besides the index to identify any element, if possible. Indexes are one of the most volatile ways to identify elements because they change whenever the layout changes, while other attributes might not.
The way to handle this type of thing is to add the attribute to the XPath, in your case the attribute would be "[@childIndex=$Question]". This would then be evaluated by XPath at runtime as "[@childIndex='1']".
I would also suggest that you make sure to have a well-defined parent for this item. Instead of 'li[2]', try to find an attribute of the li tag that is more consistent.
My final suggestion would be to find something besides the index to identify any element, if possible. Indexes are one of the most volatile ways to identify elements because they change whenever the layout changes, while other attributes might not.
Shortcuts usually aren't...
Re: Variables in Repository not getting right value
Hi,
Although I fully agree with krstcs' point about indexes and his explanation of variables being strings, there is something weird about this problem. Ranorex user guide mentions that it should be possible to use variables instead of hardcoded indexes...
http://www.ranorex.com/support/user-gui ... xpath.html
So either the user guide is wrong, or something has got broken?
Although I fully agree with krstcs' point about indexes and his explanation of variables being strings, there is something weird about this problem. Ranorex user guide mentions that it should be possible to use variables instead of hardcoded indexes...
Source:/form/button[$var]
identifies the button with index equals the value stored in the variable $var
http://www.ranorex.com/support/user-gui ... xpath.html
So either the user guide is wrong, or something has got broken?
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Variables in Repository not getting right value
Hello guys,
.. it should be possible to use a variable as an index within the RxPath.
Regards,
Robert
Unfortunately, this is not correct for variables, which are used as a wildcard for an index. As stated within our UserGuide (mentioned by odklizec):The problem is that Ranorex treats all variables in the XPath of a repo item as a single-quoted string, so it will always put the ticks around the value to make sure that the final XPath is correctly formatted. XPath requires all strings to have ticks.
.. it should be possible to use a variable as an index within the RxPath.
Regards,
Robert
You do not have the required permissions to view the files attached to this post.
Re: Variables in Repository not getting right value
I tried to use variable instead of hardcoded index and the element was found OK. So I guess there must be something else wrong?
Zoë, what version of Ranorex do you use? Could you please post a sample solution?
Zoë, what version of Ranorex do you use? Could you please post a sample solution?
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: Variables in Repository not getting right value
Ah, my bad! Thanks for the correction Robert! I'm still learning stuff... 

Shortcuts usually aren't...
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Variables in Repository not getting right value
Hi,
@krstcs
Don't worry
I'm glad that you share your experience with other users.
Regards,
Robert
@krstcs
Don't worry

Regards,
Robert