Ask a Question

How to handle if not finding on objects is not an error

cagan
Occasional Contributor

How to handle if not finding on objects is not an error

I have a teststep for saving a file. On windows you know how to save as works. It can directly  save or a pop-up window asks you do you want to overwrite with same name. Briefly, a file can be directly saved or it can overwrite. Both option is applicable for me.

 

So i don't want to take en error when save as window is appeared on the screen. Below code takes error like "Cannot obtain the window with the windowclass...." How can i fix the problem? Thank you

 

var saveAsWindow= Saveasobject

if (saveAsWindow.Exists)

{object.clickbutton();

Log.Message("overwritten button is selected.")

}

else

Log.message("overwritten window is not appeared.  Because it is a new file.")

14 REPLIES 14
mrvszn
Occasional Contributor

Hi,

 

My coworker and I tried to apply your suggestion but we still get errors when there is no window and errors when false (saveaswindow).

Screenshot is below;

Clipboard - 22 Ekim 2021 09_37.png

 

Should we have done it differently? Do you have a solution suggestion?

@React 

Thank you.

 

React
Occasional Contributor

@mrvszn Is the "saveaswindow" object found?

cagan
Occasional Contributor

Hi,

 

"saveaswindow" object is found if the Save As popup appeared. If object not found it will not do anyting actually and will just keep going test case.

React
Occasional Contributor

So you taking error before your "if statment" take pleace and in my opinion it is working as it should.

FindEx needs to be done, on an object thats exists - for example whole screen like I did.
var page = Sys.Browser().Page('*')

@cagan Change saveAsWindow declaration. It can be some parent object that you have assurance of it's existence and try again 🙂

cagan
Occasional Contributor

Hi,

Thank you for your guidance. I just want to notify that saveAsWindow can be found or not. Both case are not wrong for us. It will just do different things on both case.

So, if same file name exists then Save As popup  appear on the screen, otherwise the file directly be saved. In this condition, we couldn't keep that taking parent object what will be used for Save As popup.

cancel
Showing results for 
Search instead for 
Did you mean: