Repeat Exists (Avoid Writing Log Errors) Python
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Labels:
-
Debugging
-
Desktop Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the call to FindElement is probably the one that is logging the error. You can use other alternatives such as FindElements and 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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank for the reminder on the code editor. Didn't know anything about that.
I have a large script that loops through many user types.
And for certain user's objects are not there,
So I am using exists to find the objects, and then for other users it writes an error. (Which I would prefer not to happen)
It is actually discussed in the forum here.
.Exist method or alternative to determine whether ... - SmartBear Community
