What does find list operation return if not found? - mendix

I am using the "Find" list operation in Mendix and I would like to know what it returns if the item is not found. I could not find anything on the mendix site.

It's simple: it will return empty (Mendix' version of a null reference). It won't throw an error, but it might e.g. when the rest of the code attempts to change the empty object. It's recommended to test the result of Find with an exclusive split (the orange diamond).

Related

Ruby Capybara Element not found error handling

internet.find(:xpath, '/html/body/div[1]/div[10]/div[2]/div[2]/div[1]/div[1]/div[1]/div[5]/div/div[2]/a').text
I am looping through a series of pages and sometimes this xpath will not be available. How do I continue to the next url instead of throwing an error and stopping the program? Thanks.
First, stop using xpaths like that - they're going to be ultra-fragile and horrendous to read. Without seeing the HTML I can't give you a better one - but at least part way along there has to be an element with an id you can target instead.
Next, you could catch the exception returned from find and ignore it or better yet you could check if page has the element first
if internet.has_xpath?(...)
internet.find(:xpath, ...).text
...
else
... whatever you want to do when it's not on the page
end
As an alternative to accepted answer you could consider #first method that accepts count argument as the number of expected matches or null to allow empty results as well
internet.first(:xpath, ..., count: nil)&.text
That returns element's text if one's found and nil otherwise. And there's no need to ignore rescued exception
See Capybara docs

UiPath: Collection.contains("string") doesn't appear to be returning Boolean as expected

First I use a "Get processes" activity which assigns its result to a variable called currentProcessesCollection which is of type Collection
Next I want to check this condition in and If activity currentProcessesCollection.Contains("OUTLOOK")
I'm getting 'string' cannot be converted to type System.Diagnostics.Process'
I'm kind of flummoxed by this and wondering if anyone knows some other way to do this. I was kind of hoping that writing out the problem would help, it didn't. Thanks for any help in advance. I need to find out if outlook is running.
As you correctly said, currentProcessCollection contains a collection of Process objects. As such, Contains requires another Process object in order to compare them, when you provided the string object "OUTLOOK.EXE".
If you want to search whether at least one process by name exists, just assign the following to a boolean variable (just replace Scan with any process name):
processCollection.Where(Function(x) x.ProcessName = "Scan").Count > 0

The "getnodevalue" of HTMLUNIT not working on domattr

every time i want to get the Value of my DomAttr i get an TypeError:
My Code:
Wanted = page.getByXPath("//span[contains(.,'Some')]/parent::a/#href");
return this
[DomAttr[name=href value=URLSTRING]]
Now i want to geht the value (=URLSTRING) with Wanted.getNodeName();
but every Time i get the Error
Cannot find function getNodeValue in object [DomAttr[name=href value=
same when i use getValue
please help me
There are some things that make no sense in the code (particularly, because it is not complete). However, I think I can guess what the issue is.
getByXPath is actually returning a List (funny thing you missed the part of the code in which you specify it as a list and replaced it with a Wanted).
Note you should probably also have type warnings in the code too.
Now, you can see that the returned value is in square brackets. That means it is a List (confirming first assumption).
Finally, although you happened to miss that part of the code too, I guess you are directly applying the getValue to the list instead of the DomAttr elements in the list.
How to solve it: If you need more than 1 result iterate over the elements of the list (that Wanted word over there). If you need 1 result then user the getFirstByXPath method.
Were my guesses right?

Type mismatch error while reading lotus notes document in vb6

Am trying to read the lotus notes document using VB6.I can able to read the values of the but suddenly type mismatch error is throwed.When i reintialise the vb6 variable it works but stops after certain point.
ex; address field in lotus notes
lsaddress=ImsField(doc.address)
private function ImsField(pValue)
ImsField=pValue(0)
end function
Like this I am reading the remaining fields but at certain point the runtime error "13" type mismatch error throwed.
I have to manually reintialize by
set doc=view.getdocumentbykey(doclist)
The type mismatch error occurs for a certain field. The issue should be a data type incompatibility. Try to figure out which field causes the error.
Use GetItemValue() instead of short notation for accessing fields and don't use ImsField():
lsaddress=doc.GetItemValue("address")(0)
The type mismatch is occurring because you are encountering a case where pValue is not an array. That will occur when you attempt to reference a NotesItem that does not exist. I.e., doc.MissingItem.
You should not use the shorthand notation doc.itemName. It is convenient, but it leads to sloppy coding. You should use getItemValue as everyone else is suggesting, and also you should check to see if the NotesItem exists. I.e.,
if doc.hasItem("myItem") then
lsaddress=doc.getItemValue("myItem")(0)
end if
Notes and Domino are schema-less. There are no data integrity checks other than what you write yourself. You may think that the item always has to be there, but the truth is that there is nothing that will ever guarantee that, so it is always up to you to write your code so that it doesn't assume anything.
BTW: There are other checks that you might want to perform besides just whether or not the field exists. You might want to check the field's type as well, but to do that requires going one more level up the object chain and using getFirstItem instead of getItemValue, which I'm not going to get into here. And the reason, once again, is that Notes and Domino are schema-less. You might think that a given item must always be a text list, but all it takes is someone writing sloppy code in an one-time fix-it agent and you could end up having a document in which that item is numeric!
Checking your fields is actually a good reason (sometimes) to encapsulate your field access in a function, much like the way you have attempted to do. The reason I added "sometimes" above is that your code's behavior for a missing field isn't necessarily always going to be the same, but for cases where you just want to return a default value when the field doesn't exist you can use something like this:
lsaddress ImsField("address","")
private function ImsField(fieldName,defaultValue)
if doc.hasItem(fieldName) then
lsaddress=doc.getItemValue(fieldName)(0)
else
lsaddress=defaultValue
end if
end function
Type mismatch comes,
When you try to set values from one kind of datatype variable to different datatype of another variable.
Eg:-
dim x as String
Dim z as variant
z= Split("Test:XXX",":")
x=z
The above will through the error what you mentioned.
So check the below code...
lsaddress = ImsField(doc.address)
What is the datatype of lsaddress?
What is the return type of ImsField(doc.address)?
If the above function parameter is a string, then you should pass the parameter like (doc.address(0))

Linq - OfType<> not working as expected

I have the following code which detects all the elements in a Silverlight application beneath a certain point
then filters them to be only those of a particular type - CardButton
IEnumerable<UIElement> elementsBeneathCursor =
VisualTreeHelper.FindElementsInHostCoordinates(new Point(xPosn, yPosn), Application.Current.RootVisual);
IEnumerable<CardButton> cardsBeneathCursor = elementsBeneathCursor.OfType<CardButton>();
Even though when I inspect elementsBeneathCursor in the debugger, I can see there are 2 elements of type CardButton
Yet when I apply the OfType<> filter the resultant list is null
what's going wrong?
The resulting list won't actually be null... but the sequence will be empty, if neither of those elements is actually a CardButton. Note that OfType doesn't perform any custom conversions, so if you were expecting those to happen, that may explain it.
Try going through the unfiltered list and printing out the result of calling GetType on each element to see what it really is.

Resources