How to validate either one of two possible attributes

Ask general questions here.
Peter546
Posts: 20
Joined: Sun Jun 19, 2016 12:23 pm

How to validate either one of two possible attributes

Post by Peter546 » Sun Jun 19, 2016 12:39 pm

Hi there

I'm a beginner on Ranorex.

Not sure if this is possible. Here's the situation for our test kit. We have two printers. Plug one printer in and the name of the printer is shown at the bottom of the screen. I want to validate this UI element so that the test will pass if any one of the 2 printer names are shown at the bottom. Is it possible to do this under one test action by validating either one of two attributes against a UI element? I just want the test to look at the text.

If I create two separate test actions to validate the UI element for each name, then at least one of these tests is always going to fail because we can only plug in one printer. Eg test for printer A, test for printer B. One of these will fail so is it possible to check the text for either one of these values so that the test will pass if at least one of the text is showing.

Thanks

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

Re: How to validate either one of two possible attributes

Post by odklizec » Mon Jun 20, 2016 8:07 am

Hi,

Could you please upload a Ranorex snapshot (not screenshot!) of the element in question? Also, please post the xpath you are using to identify the control.

In my opinion, the easiest way to achieve what you want is to create a xpath containing both printer names separated by "OR" operator. E.g. something like this:

Code: Select all

//text[@innertext~'How' or @innertext~'validate']
Then simply use Validate Exists action to validate the existence of the xpath.
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

Peter546
Posts: 20
Joined: Sun Jun 19, 2016 12:23 pm

Re: How to validate either one of two possible attributes

Post by Peter546 » Mon Jun 20, 2016 9:51 am

Hi again

Thanks for the prompt response.

We've tried using the OR statement although we'r not entirely sure if this was done correctly.

I believe this is the xpath for the element

/form[@controlname='AlternateTill']/?/?/text[@accessiblename='Print After: BA-T500']

Please find attached the ranorex snapshot. I have also attached screenshots of the two printer types as previously mentioned.

Hope this is the correct information. If you need anything else please let me know.

Thanks

Peter
Attachments
printer type 2.PNG
printer type 2.PNG (9.74 KiB) Viewed 502 times
printer type 1.PNG
printer type 1.PNG (10.26 KiB) Viewed 502 times
Element Snapshot.rxsnp
(311.66 KiB) Downloaded 22 times

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

Re: How to validate either one of two possible attributes

Post by odklizec » Mon Jun 20, 2016 11:13 am

Hi,

Thanks for the snapshot and xpath. You can use for example xpath like this:
/form[@controlname='AlternateTill']/statusbar/text[@accessiblename='Print After: BA-T500' or @accessiblename='Print After: com2']
Then simply add the Validate Exists action, using the repoelement with above xpath. If there will be no or different printer used, the validation should fail.
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

Peter546
Posts: 20
Joined: Sun Jun 19, 2016 12:23 pm

Re: How to validate either one of two possible attributes

Post by Peter546 » Mon Jun 20, 2016 2:08 pm

Working now. That's great. Thanks for your help. I'll add this to my knowledge database :D