Page 1 of 1

Certain lookup values are not selected

Posted: Fri Apr 15, 2011 4:48 pm
by Saha
Hi,

I have a function which checks for all lookup values in combo box fields in the application.
It works for most of the lookups for fails for few items .
For example- Below mentioned are the lookups which is not selected while excuting. Cursor moves to the left most corner of the window and the lookup value is not selected in the combo box. It does not through any exception but continues with the next value in the list.

Any idea what is missing here.
Lookups
-----------
3 Payments (Equal) - 33.3% per payment
4 Payments (Equal) - 25% per payment
3 Payments (50% 1st Payment, 25% for the next 2 Payments)
3 Payments (40% 1st Payment, 30% for the next 2 Payments)

Thanks,
Saha

Re: Certain lookup values are not selected

Posted: Fri Apr 15, 2011 5:02 pm
by Ciege
Which ones (or a sample of) does it select properly?
What's different between the ones that work and the ones that don't?
Can you share you code that does the work?

Re: Certain lookup values are not selected

Posted: Fri Apr 15, 2011 5:43 pm
by Saha
Fails for all these
3 Payments (Equal) - 33.3% per payment
4 Payments (Equal) - 25% per payment
3 Payments (50% 1st Payment, 25% for the next 2 Payments)
3 Payments (40% 1st Payment, 30% for the next 2 Payments)

Works fine for all other list items in the same combo box. some example of values which works fine.
Public vehicle infraction
At the Same Time Each Day
Job by Job Basis

Code -
Public Sub CheckLookupInUI(lookupItem As String, fieldName As String)
	Dim elementName As String = Nothing
	Dim isElementFound As Boolean = False
	Dim isLookupFound As Boolean = False
	Dim item As ListItem = Nothing
	Dim element As WebElement = Nothing
	'MsgBox("fieldName:"&fieldName)
	elementName = GetElementName(fieldName)
	'MsgBox("Element Name :" &elementName)
	Report.Info("lookup-"&lookupItem)
	isElementFound = webDoc.TryFindSingle(".//select[@id~'.*" & elementName & "$']", Adapter.DefaultSearchTimeout, element)
	If (isElementFound and element.EnsureVisible) Then
		element.focus()
		element.Click(Location.Center, 100)
		'msgBox(lookupItem)
		isLookupFound = Host.Local.TryFindSingle(".//listitem[@accessiblename='" &lookupItem & "']", Adapter.DefaultSearchTimeout, item)
		If (isLookupFound) Then			
			item.Click(Location.Center, 100)
		Else Report.Failure("Combo value not found-" &lookupItem)
		End If
	Else Report.Failure("Element not found :" &fieldName)
	End If
	
End Sub

Re: Certain lookup values are not selected

Posted: Fri Apr 15, 2011 5:45 pm
by Saha
Forgot to answer your seond question
Only difference i see in the list values which does not work in it has '%' , '-' in it.

Re: Certain lookup values are not selected

Posted: Fri Apr 15, 2011 5:53 pm
by Ciege
I agree... It sure looks like it is failing due to the special characters in the LookupItem.

Try spying on the values in question and see how RanorexSpy resolves the special characters. Since you are using a regular expression in your XPath you may need to put in some extra formatting code if your LookupItem contains special characters then you may need to add in some escape characters.

Re: Certain lookup values are not selected

Posted: Mon Apr 18, 2011 6:04 pm
by Saha
I have tried with spy and I am able to see the lookup values properly without any special formatting.
I have attached the snapshot for this lookup field.

Thanks,
Saha

Re: Certain lookup values are not selected

Posted: Mon Apr 18, 2011 6:07 pm
by Ciege
Well, I may have misspoke... Since Spy is not representing the elements using a regular expression, it probably won't show escaped characters. But, since you are using a regular expression in your code you will need to escape the special characters properly according to RegEx standards.

Re: Certain lookup values are not selected

Posted: Tue Apr 19, 2011 8:09 am
by Support Team
Hi,

I have tried your code and it is working like a charm. I had to replace your GetElementName method, but I think this method shouldn't be the problem. But could you please post this piece of code too?

I think it's not the RegEx. You don't use this for the list items, only for the ComboBox the RegEx is used and this shouldn't be a problem, because there are no special characters inside the ID attribute.
Saha wrote:cursor moves to the left most corner of the window and the lookup value is not selected in the combo box.
Do you get any warning in your report if Ranorex clicks to "0;0"?
Have you tried to put a short delay after you click the combobox?

Regards,
Peter
Ranorex Team

Re: Certain lookup values are not selected

Posted: Wed Apr 20, 2011 6:35 pm
by Saha
Hi Peter,

No I have not got any warning in report.
No I have not added any delay, as my lookup search work for most of the lookups.

Did this work for you with the specific lookup values which I have mentioned in the previous thread?
For example -
3 Payments (Equal) - 33.3% per payment
4 Payments (Equal) - 25% per payment
3 Payments (50% 1st Payment, 25% for the next 2 Payments)
3 Payments (40% 1st Payment, 30% for the next 2 Payments)


GetElementName method just look for the element in an access db and give the element ID back.

Re: Certain lookup values are not selected

Posted: Thu Apr 21, 2011 9:56 am
by Support Team
Hi,

Please take a look to the attached project. I've used your code and also the HTML page I have used is inside the zip file.

Regards,
Peter
Ranorex Team
vb_RanorexTest.zip