Page 1 of 1

Value which needs scrolling not getting selected

Posted: Fri Jan 25, 2013 1:08 pm
by varun
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.

Re: Value which needs scrolling not getting selected

Posted: Sat Jan 26, 2013 1:35 pm
by varun
Hi Support,
I am desperately waiting for your response. Can you please provide me with your valuable feedback ASAP.

Thanks,
Varun.

Re: Value which needs scrolling not getting selected

Posted: Mon Jan 28, 2013 4:09 pm
by Ciege
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...

Re: Value which needs scrolling not getting selected

Posted: Tue Jan 29, 2013 5:55 am
by varun
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.

Re: Value which needs scrolling not getting selected

Posted: Tue Jan 29, 2013 4:00 pm
by Ciege
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.

Re: Value which needs scrolling not getting selected

Posted: Wed Jan 30, 2013 1:26 pm
by varun
Hi Ciege,

Thanks for your stuff. I achieved this :)

Regards,
Varun.

Re: Value which needs scrolling not getting selected

Posted: Wed Jan 30, 2013 4:05 pm
by Ciege
Great! Glad you got it figured out!