User code IF statement on a text field existence

Ranorex Spy, Recorder, and Studio.
travisSAEG
Posts: 2
Joined: Thu Oct 08, 2020 9:30 pm

User code IF statement on a text field existence

Post by travisSAEG » Fri Oct 09, 2020 1:47 pm

I am creating user code in Ranorex for an IF statement that revolves around whether or not a text count field is there or not. The xpath to the field (repo element name is dayCount) that spy has right now is: ?/?/text[@name='60']

So I am going to use pseudocode here to denote what I want and what problem I am seeing.

IF (repo.dayCount.Exists())
{
move slider bar
} else {
report message
}

When I try using Exists I get an error during the build that says "Text does not contain a definition for Exists......."

What should I use to test for the existence of this element or what am I missing? I am very new to Ranorex.
I am using Ranorex 9.1.0
I am testing a desktop app in windows 10
I am using C#.

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

Re: User code IF statement on a text field existence

Post by odklizec » Sun Oct 11, 2020 10:38 pm

Hi,

You should use RepoItemInfo element, instead of Adapter element, like this...

Code: Select all

repo.dayCountInfo.Exists()
Ideally, pass the repo element to code via RepoItemInfo method parameter...

Code: Select all

YourMethod(RepoItemInfo nameOfElement)
{
IF (nameOfElement.Exists())
    { 
        move slider bar
...
}
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

travisSAEG
Posts: 2
Joined: Thu Oct 08, 2020 9:30 pm

Re: User code IF statement on a text field existence

Post by travisSAEG » Mon Oct 12, 2020 1:13 pm

Thank you for the response. I found and implemented the same solution late in the day on Friday. Your response just confirms I was on the right path.