Value which needs scrolling not getting selected

Ranorex Spy, Recorder, and Studio.
varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Value which needs scrolling not getting selected

Post by varun » Fri Jan 25, 2013 1:08 pm

Hi Support,

In Desktop application, I want to select value from drop-down which needs scrolling. But its not working with this code snippet-

Code: Select all

methodcall()
{
MethodName("ElementName", Variable);
}

public static int MethodName(string ComboName, string ComboItem)
        {
        	try
        	{
        		Thread.Sleep(500);
        	}

        	catch (RanorexException e)
        	{
        		Report.Error("Unable to find ComboBox: " + ComboName);
        		Console.WriteLine(e.ToString());
        		Report.Screenshot();
        		return -1;
        	}

        	try
        	{
        		Report.Info("Selecting item: " + ComboItem + " in  ComboBox: " + ComboName);
        		Thread.Sleep(1000);
        		//      Thread.Sleep(1000);
        		ComboBox item = "/container[@controlname='nextActiveControl']/listitem[@text='" + ComboItem + "']";
//        		ListItem item = "/container/container[@controlname='nextActiveControl']/listitem[@text='" + ComboItem + "']";

        		if (item.Visible == false)
        		{
        			Keyboard.Press("{HOME}");
        			Thread.Sleep(500);
        			while (item.Visible == false)
        			{
        				Keyboard.Press("{PageDown}");
        				Thread.Sleep(500);
        			}
        		}

        		item.Click(Location.Center, 1000);
        		Report.Debug("  Selected item: " + ComboItem + " in  ComboBox: " + ComboName);
        	}

        	catch (RanorexException e)
        	{
        		Report.Error(e.ToString());
        		Report.Screenshot();
        		return -1;
        	}

        	return 0;
        }
Can you please elaborate what needs to correct here? Please find RX snapshot of Drop-down and screenshot of error from RX log.

Thanks in advance,
Varun.
Attachments
WBDropdown_ErrorLog.png
ErrorLog
WBDropdown_ErrorLog.png (17.25 KiB) Viewed 977 times
WBDepDropdown.rxsnp
RXSnapshot_Dropdown
(413.51 KiB) Downloaded 225 times

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Value which needs scrolling not getting selected

Post by varun » Sat Jan 26, 2013 1:35 pm

Hi Support,
I am desperately waiting for your response. Can you please provide me with your valuable feedback ASAP.

Thanks,
Varun.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Value which needs scrolling not getting selected

Post by Ciege » Mon Jan 28, 2013 4:09 pm

One quick thing I see in your error is that there seems to be a space at the end of the list item name "PNN10 ". Is that space supposed to be there? That could be causing your element not found exception...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Value which needs scrolling not getting selected

Post by varun » Tue Jan 29, 2013 5:55 am

Hi Ciege,

Item "PNN10" which is appearing in log with single space has actually 5 spaces after it. This could also be the secondary reason for failure of test case but my main concern is that tool fails to scroll up/down the list of drop-down. At-least it should look for the item by scrolling down if requested item is not in first visible area.

I have modified your code to work with desktop application, but not sure if something is wrong with code or ...

Can you please review the RX snapshot and code snippet and let me know whats wrong with the test case.
Once we are done with this, I will surely try to work with 5 spaces of drop-down items.

Thank you in advance,
Varun.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Value which needs scrolling not getting selected

Post by Ciege » Tue Jan 29, 2013 4:00 pm

Well the way you have the code there it will never get to the "if (item.Visible == false)" line if the ComboBox Item is not found. Since the exception is thrown it will drop to the Catch block and present the exception in the log (as you have seen).

Since in your case it seems as if you are passing an invalid list item that does not exist so the code is behaving properly and dropping to the exception catch.

I cant load your snapshot, maybe different version of Ranorex... In any case, when you view your combobox in RanorexSpy, are all the list items found or only the visible ones? If only the visible ones then you need to modify the code to, instead of throwing an exception on item not found, place the scrolling code into the catch block. Only throw the exception if the listitem is not found AND you are at the end of your list.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Value which needs scrolling not getting selected

Post by varun » Wed Jan 30, 2013 1:26 pm

Hi Ciege,

Thanks for your stuff. I achieved this :)

Regards,
Varun.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Value which needs scrolling not getting selected

Post by Ciege » Wed Jan 30, 2013 4:05 pm

Great! Glad you got it figured out!
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...