How to display warning messages when the element does not exist

Ask general questions here.
[email protected]@
Posts: 18
Joined: Fri Dec 27, 2019 12:16 pm

How to display warning messages when the element does not exist

Post by [email protected]@ » Mon Mar 30, 2020 5:59 pm

Hi,
I have a problem as follows:
If the element does not exist, it will display a warning message. But it does not work as expected and displays the following warning:
(Optional Action) No element found for path '/dom[@domain='A']//div[#'alarm-container']//li[@class='status-new']' at step 'descendant-or-self::div[#'alarm-container']' after 32 attempts within 10s.
This is is code of me

Code: Select all

if(repo.AquaSmartClound.AlarmSumaryScreen.dataStatusNewInfo.Exists(2000)==false)
    		{
        		Report.Warn("Data Test","It does not exist data with the state being new");
        	}
Please help me.
Thanks

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

Re: How to display warning messages when the element does not exist

Post by odklizec » Mon Mar 30, 2020 6:24 pm

Hi,

You are getting this error most probably because the failing element is attached to an optional action in recording module (before or after your user code)? Please check your recording.

If you don’t like to see such message, you have to convert the “optional” action to user code and enclose it in Exists() condition, so then the action will be performed only if the element exists. And if it does not exists, there will be displayed your coded warning. Hope this helps?
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

[email protected]@
Posts: 18
Joined: Fri Dec 27, 2019 12:16 pm

Re: How to display warning messages when the element does not exist

Post by [email protected]@ » Tue Mar 31, 2020 5:05 am

Hi,
Thanks for the answer.
odklizec wrote:
Mon Mar 30, 2020 6:24 pm
If you don’t like to see such message, you have to convert the “optional” action to user code and enclose it in Exists() condition
I don't know how to perform such as you talk, Can you give me specific instructions?
I knew why a warning "optional action" message is displayed
Because I set "continue to fail" to be true
after that, I set "use item logging by default" to be false, the "option action" warning is not displayed, but my coded warning is still not displayed.

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

Re: How to display warning messages when the element does not exist

Post by odklizec » Tue Mar 31, 2020 8:39 am

Hi,

Unfortunately, without seeing your project, it's hard to provided a reasonable suggestion. I don't know where exactly is used your code? Could you please post your solution here, so we can look at it?

Basically, if you don't want to see the generic error message, regarding missing repo element and generated by Ranorex, you must enclose all steps linked with potentially not-available repo element(s) in the condition from your first post. There is currently no support for code-less conditions directly in recording modules. It's something Ranorex folks possibly already working on (see Ranorex road map). But as of now, it must be done in code.

The easiest way, how to convert recorded steps to user code, is simply select affected step or steps, right click on selection and from the appeared menu select Convert to user code.../Merge items to user code.... Then go to the created user code and add the condition of your choice. Hope this helps?
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