XPath Assistance

Best practices, code snippets for common functionality, examples, and guidelines.
tbumbarger
Posts: 6
Joined: Tue Apr 18, 2017 6:58 pm

XPath Assistance

Post by tbumbarger » Tue Apr 18, 2017 7:57 pm

I am trying to click on a button that is in a repeater. So each row has it's own.

The XPath from Ranorex Spy is:

Code: Select all

/dom[1]//div[#'saValues']/article[3]//a[@innertext~'^ Edit\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ']
I want to find the row by text, and then click on it's associated button. I'm able to find the index of the row I want, but I'm having trouble telling ranorex where to click.

My current failing code looks like:

Code: Select all

Button button = repo.Records.FindSingle<Button>("./article[" + i.ToString() + "]//a[@innertext~'Edit']");
If I add the "\\\\\" after it can't compile because it's an escape character.
It says that it cannot map the element to a button. I've tried the FlexElement class as well with no luck.

Does anyone have any suggestions? Thanks!

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

Re: XPath Assistance

Post by odklizec » Wed Apr 19, 2017 11:27 am

Hi,

Please post a Ranorex snapshot of the problematic element. It's the quickest and most reliable to way to get correct answer.
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

tbumbarger
Posts: 6
Joined: Tue Apr 18, 2017 6:58 pm

Re: XPath Assistance

Post by tbumbarger » Wed Apr 19, 2017 4:11 pm

Sorry about that, I've attached a snapshot. Hopefully that is what you were looking for.
Last edited by tbumbarger on Tue Jun 06, 2017 2:38 pm, edited 1 time in total.

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

Re: XPath Assistance

Post by odklizec » Thu Apr 20, 2017 7:20 am

Hi,

I guess you want to identify the Edit button based of the hospital name, (e.g. Heber Valley Hospital), right? So then the xpath should look like this:

Code: Select all

/dom[@domain='10.180.224.8:8100']//div[#'saValues']/article/div//span[@title='fac.Description' and @innertext~'Heber Valley Hospital']/../..//a[@innertext~'Edit']
. Now because you most probably don't want to have the hospital name hardcoded in repo, all you need to do is to replace the InnerText Heber Valley Hospital with repo variable and connect it to a data connector. That's all. There is no need to search the button via code at all ;)
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

tbumbarger
Posts: 6
Joined: Tue Apr 18, 2017 6:58 pm

Re: XPath Assistance

Post by tbumbarger » Fri Apr 21, 2017 6:12 pm

Got it! Thanks very much. Putting the whole thing into the repo and then just altering what I wanted did the trick.