How to read an attachment name in a opened message in OL2007

Ask general questions here.
cancerion
Posts: 30
Joined: Tue Jun 16, 2009 6:15 pm

How to read an attachment name in a opened message in OL2007

Post by cancerion » Tue Aug 18, 2009 5:48 am

Hi,

I want to read a attachment name in a opened message in OL 2007 and with below code I am not getting proper child count in attachment list.

It identifies only Message in attachment list.
For example:If there is one attachment in a message,it shows child count as 1 i.e. only for message not for attachment

Is there any other way to query for attachment in an opened message?


string path = "/form[@title~'" + "- Message" + "']";
Ranorex.Form FrmMsg = Host.Local.FindSingle(path, 10000);
Delay.Duration(InitClass.nElementLoadTime);
Element elemList1 = FrmMsg.FindSingle<Ranorex.List>("element[@controlid='103']/element[@controlid='258']/container[@caption='']/element[@controlid='4623']/list[@accessiblename='Attachments']");

for (int n = 0; n < elemList.Children.Count; n++)
{
if (n == 0)
continue;
Ranorex.ListItem listitem2 = elemList1.Children[n].As<Ranorex.ListItem>();
string AttachName1 = listitem2.Text;
}

Thanks,
Sachin

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read an attachment name in a opened message in OL2007

Post by Support Team » Tue Aug 18, 2009 12:54 pm

Hi!
I`ve tested your issue in Outlook 07 and i get the attachment list items correctly!
What shows Ranorex Spy when you`re tracking the List 'Attachments' item?

Regards,
Christian
Support Team
.
Image

cancerion
Posts: 30
Joined: Tue Jun 16, 2009 6:15 pm

Re: How to read an attachment name in a opened message in OL2007

Post by cancerion » Tue Aug 18, 2009 1:25 pm

When I track attachment list using Ranorex Spy, It shows correctly. It shows attachment name as listitem under list Node. Even while debugging the snippet given above sometimes it gave right children count of list.

But most of the time it doesn’t give attachment name as part of test case using this way to get attachment name.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read an attachment name in a opened message in OL2007

Post by Support Team » Tue Aug 18, 2009 2:01 pm

If the ListItem in Ranorex Spy shows up the items correctly it also should in code. They are working on same base.
Probably your RxPath is wrong in some cases. Do you get the correct list 'attachment' item every time you call your testcase?

Try to do the following:
Drag 'n Drop the 'attachment' item from project browser into your source-code.
Iterate through the 'ListItem' children like:
// sample code
List listAttachments = "/form[@title='Inbox - Microsoft Outlook']/container[@caption='']/container/*/element/container[@caption='']/element[@controlid='4623']/list[@accessiblename='Attachments']";
 foreach(ListItem item in listAttachments.FindChildren<Ranorex.ListItem>())
 {
   if(item.Index==0)
     continue;
   string itemText = item.Text;         	
 }
Regards,
Christian
Ranorex Support Team
.
Image

cancerion
Posts: 30
Joined: Tue Jun 16, 2009 6:15 pm

Re: How to read an attachment name in a opened message in OL2007

Post by cancerion » Wed Aug 19, 2009 6:04 am

Thanks for your reply
I am trying with right RxPath. Even I tried with using object repository.

I can read the attachment name from Reading pane in Outlook already.
But my requirement is to read it from opened message in OL2007 .But still it doesn’t give child count correctly. That’s why I can not read the attachment name.

Thanks,
Sachin

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read an attachment name in a opened message in OL2007

Post by Support Team » Wed Aug 19, 2009 7:58 am

I just tried that, Ranorex identifies the attachments as a List, so everything seems to be perfect. Just note, that the "Message" is the first item in the attachments.

Why not enable element highlighting in Ranorex Spy (toolbar button), so you can see which element you are currently tracking? (see http://www.ranorex.com/support/user-gui ... x-spy.html is you can't find the right toolbar button)

Regards,
Alex
Ranorex Support Team
.
Image

cancerion
Posts: 30
Joined: Tue Jun 16, 2009 6:15 pm

Re: How to read an attachment name in a opened message in OL2007

Post by cancerion » Wed Aug 19, 2009 9:33 am

If message has one attachment, how many children it is showing for list object?
Can you please try to read the attachment name as a listitem in the list?

I am also getting the list object; if message has one attachment then it should show child count as 2 for list object. But it shows child count one i.e. only for Message not for attachment.

I can see the property of list and listltems in the Ranorex Spy. But I need to read attachment name generically so I am trying to get it from list object.

There is nothing wrong in getting the object of the list.

Thanks,
Sachin

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read an attachment name in a opened message in OL2007

Post by Support Team » Wed Aug 19, 2009 10:06 am

cancerion wrote:If message has one attachment, how many children it is showing for list object?
Exactly two, always.

I just pasted the code from your original post into a sample project and it worked for me, the only thing I had to change was the "elemList" variable that is not defined. I changed its name to "elemList1".

Do you have a variable "elemList" somewhere defined in your code? Could it be that your just using the wrong variable?

Regards,
Alex
Ranorex Support Team
.
Image

cancerion
Posts: 30
Joined: Tue Jun 16, 2009 6:15 pm

Re: How to read an attachment name in a opened message in OL2007

Post by cancerion » Wed Aug 19, 2009 11:56 am

I have given right name in my local copy.But still giving me problems with Windows XP/OL2007.

Even I tried with object repository where i don't need to create a list.I am directly calling children of attachment.

foreach (ListItem item in ObjectRepository.InitClass.objRepo.FormFWColon_Test_Mail_for_Fo.ListAttachments.
FindChildren<Ranorex.ListItem>())
{
if (item.Index == 0)
continue;
string itemText = item.Text;
}

listattachment definition is:

/// <summary>
/// The ListAttachments item.
/// </summary>
public virtual Ranorex.List ListAttachments
{
get
{
return CreateAdapterForPath<Ranorex.List>("ListAttachments", "element[@controlid='103']/container/element[@controlid='4623']/list[@accessiblename='Attachments']", 60000, null);
}
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read an attachment name in a opened message in OL2007

Post by Support Team » Wed Aug 19, 2009 12:40 pm

Please describe your issue more detailed. Outherwise it`s very hard to support. What exactly do you want to do and in which case does the problem occur? Do you get an 'ElementNotFoundException' ?

Maybe your RxPath is changing when you navigate thru the outlook items (e.g. form title...)
Try to use the following RxPAth for the ListAttachment: /form[@title~'Microsoft\ Outlook']/container/container/*/element/container/element[@controlid='4623']/list[@accessiblename='Attachments'] which uses RegEx for the form title.

Regards,
Christian
Support Team
.
Image

cancerion
Posts: 30
Joined: Tue Jun 16, 2009 6:15 pm

Re: How to read an attachment name in a opened message in OL2007

Post by cancerion » Thu Aug 20, 2009 5:42 am

As I have mentioned in my previous posts, I need to read an attachment name in an opened message in OL2007 only. I can read it from Outlook reading pane also.
But my test case requirement is to check the attachment in an opened message.

With Ranorex 2.1.2, we have to approaches; one with using objects repository and another directly using RxPath.

I have tried both to get the attachment name, but both gave children in attachment list only one.
You can see my code snippets used in previous posts.

It doesn’t give any ElementNotFoundException exception.It doesn’t give the attachment name.
Whenever I want to use this attachment name, it shows as null.

Thanks,
Sachin

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read an attachment name in a opened message in OL2007

Post by Support Team » Thu Aug 20, 2009 8:27 am

Well, I tried with an opened message, not in the reading pane (actually I tried both versions). Everything worked out allright. I even tried with the code you posted and got the right result (except that I needed to change a variable name as I mentioned earlier).

Did you ever get your code to work? Does it always fail or only sometime? Are your sure that your are searching in the right opened message window?

What version of Outlook do you use? Have you installed all the latest updates?
And please update to Ranorex 2.1.3!

Regards,
Alex
Ranorex Support Team
.
Image