How can I record a generic xpath without the machine name

Best practices, code snippets for common functionality, examples, and guidelines.
fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

How can I record a generic xpath without the machine name

Post by fester13579 » Wed Aug 24, 2016 4:26 pm

I am currently building my 1st WEB based test cases on “MachineA” but will later run this on “MachineB,C,D...”.

While building my recordings, each click is recording the full path of A in every xpath and I then have to edit every single one to use a regex match on a substring so that it will still match when running on B.

Is there a way to make the recorder not be so literal and thereby save me the re-editing time on all my clicks.

I thought perhaps this would help but apparently it does not
The unique ID search can be enabled/disabled within the “General settings” -> 'Enable search by unique ID (if available)'. “

Thanks...
foo2.png
foo2.png (190.66 KiB) Viewed 630 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How can I record a generic xpath without the machine name

Post by Support Team » Thu Aug 25, 2016 1:55 pm

Hi fester13579,

I would suggest trying to work around this issue as follows.
  • Track the IFrame element with Ranorex Spy and add it to the repository
    add_to_repository.png
    add_to_repository.png (10.35 KiB) Viewed 616 times
  • Convert the item to a rooted folder
    convert_to_rooted_folder.png
    convert_to_rooted_folder.png (6.84 KiB) Viewed 616 times
  • Edit the path for the rooted folder via the Path Editor and apply the regular expression
  • As a consequence, new recorded or tracked items will be located within this rooted folder and you won't need to adjust the regular expression again and again
    repository_result.png
    repository_result.png (7.77 KiB) Viewed 616 times
Alternatively, you could try creating a RanoreXPath Weight Rule that prefers a different attribute when generating the path (assuming that there is a different attribute that could be used for identifying the IFrame).

If you need more information please do let me know.

Sincerely,
Johannes
.
Image

fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

Re: How can I record a generic xpath without the machine name

Post by fester13579 » Fri Aug 26, 2016 3:21 pm

Thank you...