Forum Discussion

M_Schofer_1111's avatar
M_Schofer_1111
Occasional Contributor
12 months ago

Repeat Exists (Avoid Writing Log Errors) Python

This is a script I have pared down in the utter hope I can make my slf clear.

 

I an using different users in loops and some elements do not exist for certain users. 

I am using exists to see if an item exists,

If it doesn't exist, it writes errors to the log.--I dont want this.

Documentations says to use this methodology.

 

if (Sys.Process("notepad").WaitWindow("#32770", "About Notepad", 1, 5000).Exists):
  # Notepad is running
else:
  # Notepad is not running

My code snippet

 

def a1():
try:
# # finds the link and verifies it exists on page
# myLinkXPath = "//a[text()='Purchase Inquiry']"
# myTestLink = JCCommon.verify_link(myLinkXPath)
# myTestLink.Click()
#
browser = Aliases.browser
CurrPage = browser.Page("*")
CurrPage.Wait()

myPT = CurrPage.FindElement("//font[.='Purchase Types']")      

if myPT.Exists:                                              -This works or throws an error if it doesn't exist.
Log.Message("I am the Rain Queen")

if myPT.WaitWindow("#32770","Wait Window",-1,10000).Exists: Per Documentation however this doesn't work. 
Log.Message("Found Purchase Type Header")
else:
Log.Message('Not Found Purchase Type')
except Exception as e:
myErrMessage = JCCommon.capture_error(e)
Log.Error(myErrMessage)

 

3 Replies

  • MarkHays's avatar
    MarkHays
    Occasional Contributor

    I think the call to FindElement is probably the one that is logging the error.  You can use other alternatives such as FindElementand then get a list of elements (list would contain nothing in this case) and go from there.      

     

    I do agree that when FindElement cannot find something it logging an error is problematic, and it would be good if they had an optional parameter to log an error or not.   

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    "Documentations says to use this methodology" - which document are you referring too?

     

    So you output a message "I am the Rain Queen" if you have found the element "Purchase Types" in your web page?

     

    You are then waiting for a window or dialog to appear named "Wait Window", which doesn't appear? So it performs the code for "Not Found Purchase Type". I don't understand what except does?

     

    Use the code editor to attach your code, as it keeps the format