html select box

Ask general questions here.
chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

html select box

Post by chunkylover53 » Fri Oct 08, 2010 7:53 pm

Hi,
How do I select the options in an html select box on a web page? I want to cycle through all the items dynamically.
My code looks like this:

WebDocument modelPage = "/dom[@caption='Models Page']";

SelectTag models = modelPage.FindSingle(".//select[@id='cphContent_ddlFilter']");


options = models.Options;
foreach(OptionTag anOption in options)
{
what do I do to select each option?
}
Any info will be much appreciated.
Thank You
CL

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

Re: html select box

Post by Ciege » Fri Oct 08, 2010 10:40 pm

This is how I do it.
Find the combobox and click it to open it.
Search the resulting list for a specific item.
Click that item.

Code: Select all

{
//click the combo box
models.Click(Location.CenterRight, 1000);
//Find the list item you want to click
ListItem item = "/container[@caption='selectbox']/listitem[@text='" + ComboItem + "']";
//Click the item
item.Click(Location.Center, 1000);
}
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...

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Wed Oct 13, 2010 10:25 pm

Hi,

Sorry but that doesn't work for a variety of reasons.
I can't click the control because I'm using IE. The click method doesn't work in IE so I can't expand the combo box. PerformClick doesn't work either.
This is a web page and not a desktop app.
I dont' know the contents of the drop down. I need to find it dynamically.
This just doesn't work: /container[@caption='selectbox']/listitem because it's not in my ranorexpath to the control. My ranorexpath looks like this: /dom[@domain='192.168.245.138']/body/form/div[3]/div[@id='middle']/div/div/div[@id='content']/div/div[1]/div/div[1]/select[@id='cphContent_ddlFilter']
Any other way to find it?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: html select box

Post by Support Team » Thu Oct 14, 2010 10:15 am

Hi,

Cieges code is working as expected. Here is a full example to open and click the combo box in Internet Explorer for your issue with an loop.
WebDocument web = "/dom[@page='combo.html']";
SelectTag selectTagS = web.FindSingle(".//select[@name='s']");

//Open Combobox to get the container
selectTagS.Click();                
//Searching for the container containg the list items
IList<Ranorex.ListItem> optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem");
foreach(ListItem listItem in optionList)
{
	//Open combobox
	selectTagS.Click();
	//Click list item
	listItem.Click();
}
chunkylover53 wrote:This just doesn't work: /container[@caption='selectbox']/listitem because it's not in my ranorexpath to the control. My ranorexpath looks like this: /dom[@domain='192.168.245.138']/body/form/div[3]/div[@id='middle']/div/div/div[@id='content']/div/div[1]/div/div[1]/select[@id='cphContent_ddlFilter']
Your RanoreXPath is the RxPath to the combo box in the website. But if you open the combo box, there will be generated a container where the list items are nested. I would suggest you to use the Recorder and take a look to the generated code of the Recorder how he handles this issue.

Regards,
Peter
Ranorex Team

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Thu Oct 14, 2010 3:43 pm

Hi,
Thanks for the info. The selectTags.Click doesn't expand the dropdown, so I don't think I can get to the container.
The optionList keeps coming back as null as a result.
How do I expand the drop down?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: html select box

Post by Support Team » Thu Oct 14, 2010 3:58 pm

Hi,

Please post your code so I can check it.

Thanks in advance.

Regards,
Peter
Ranorex Team

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Thu Oct 14, 2010 6:01 pm

WebDocument reportingPage = "/dom[@caption='PortalPage']";

SelectTag models = reportingPage.FindSingle("/dom[@domain='192.168.245.138']/body/form/div[3]/div[@id='middle']/div/div/div[@id='content']/div/div[1]/div/div[1]/select[@id='cphContent_ddlFilter']");

models.Click();

IList<Ranorex.ListItem> optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem");

foreach(ListItem listItem in optionList)
{
//Open combobox
models.Click();
//Click list item
listItem.Click();
}

Thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: html select box

Post by Support Team » Fri Oct 15, 2010 10:23 am

Hi,

Please use following code for the SelectTag instead of yours.
SelectTag models = reportingPage.FindSingle(".//select[@id='cphContent_ddlFilter']");

Regards,
Peter
Ranorex Team

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Fri Oct 15, 2010 5:35 pm

Hi,
Okay, I tried that and it still didn't work. The optionList is still coming back as empty. This doesn't seem to work: IList<Ranorex.ListItem> optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem");

I don't understand why it works with the recorder but not in my code.

Thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: html select box

Post by Support Team » Sun Oct 17, 2010 1:42 pm

chunkylover53 wrote:I don't understand why it works with the recorder but not in my code.
How does the code that Ranorex Recorder generates look like - could you post the code?

Some more things that could be interesting:
  • Did you try using the code generated by the recorder? What's the RanoreXPath of the repository item used by Ranorex Recorder?
  • Could you post two Ranorex snapshots of the drop down: One when the drop down is closed and one when it's opened? (How to create a Ranorex Snapshot...)
  • Is the thread executing the code running in STA mode; i.e. is the Main method marked with the "STAThread" attribute?
Usually, when you open a drop down in IE, Ranorex identifies this drop down as a top-level "container" element with "listitem" elements as children. So, the code suggested by Peter should work. That's why I would like to see a snapshot of the drop down.

Regards,
Alex
Ranorex Team

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Tue Oct 19, 2010 10:29 pm

Hi,
I don't see in the ranorex recorder code where it's manipulating the drop down.
See code below.
Yes the STAThread attribute is present.
Also see attached screen shots.
///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// DO NOT MODIFY THIS FILE! It is regenerated by the designer.
// All your modifications will be lost!
// http://www.ranorex.com
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Repository;

namespace PortalWebTests
{
	/// <summary>
	/// The class representing the PortalWebTestsRepository element repository.
	/// </summary>
	[System.CodeDom.Compiler.GeneratedCode("Ranorex", "2.3.4")]
	public partial class PortalWebTestsRepository : RepoGenBaseFolder
	{
		static PortalWebTestsRepository instance;

		/// <summary>
		/// Gets the singleton class instance representing the PortalWebTestsRepository element repository.
		/// </summary>
		public static PortalWebTestsRepository Instance {
			get { return instance; }
		}

		/// <summary>
		/// Repository class static constructor.
		/// </summary>
		static PortalWebTestsRepository()
		{
			instance = new PortalWebTestsRepository();
		}

		PortalWebTestsRepositoryFolders.WebDocumentSearchandise_ReportalAppFolder _webdocumentsearchandise_reportal;
		PortalWebTestsRepositoryFolders.ContainerSelectboxAppFolder _containerselectbox;

		/// <summary>
		/// Repository class constructor.
		/// </summary>
		public PortalWebTestsRepository() : base("PortalWebTestsRepository", "", null, 30000, false)
		{
			_webdocumentsearchandise_reportal = new PortalWebTestsRepositoryFolders.WebDocumentSearchandise_ReportalAppFolder(null);
			_containerselectbox = new PortalWebTestsRepositoryFolders.ContainerSelectboxAppFolder(null);
		}

		/// <summary>
		/// The WebDocumentSearchandise_Reportal folder.
		/// </summary>
		public virtual PortalWebTestsRepositoryFolders.WebDocumentSearchandise_ReportalAppFolder WebDocumentSearchandise_Reportal
		{
			get { return _webdocumentsearchandise_reportal; }
		}

		/// <summary>
		/// The ContainerSelectbox folder.
		/// </summary>
		public virtual PortalWebTestsRepositoryFolders.ContainerSelectboxAppFolder ContainerSelectbox
		{
			get { return _containerselectbox; }
		}
	}

	/// <summary>
	/// Inner folder classes.
	/// </summary>
	public partial class PortalWebTestsRepositoryFolders
	{
		/// <summary>
		/// The WebDocumentSearchandise_ReportalAppFolder folder.
		/// </summary>
		public partial class WebDocumentSearchandise_ReportalAppFolder : RepoGenBaseFolder
		{
			private RepoItemInfo _somedivtagInfo;
			private RepoItemInfo _selfInfo;

			/// <summary>
			/// Creates a new WebDocumentSearchandise_Reportal  folder.
			/// </summary>
			public WebDocumentSearchandise_ReportalAppFolder(RepoGenBaseFolder parentFolder) :
					base("WebDocumentSearchandise_Reportal", "/dom[@domain='192.168.245.138']", null, 30000, true)
			{
				_somedivtagInfo = new RepoItemInfo(this, "SomeDivTag", "body/form/div[3]/div[@id='middle']/div/div/div[@id='right']/div[1]/div", 10000, null);
				_selfInfo = new RepoItemInfo(this, "Self", "", 30000, null);
			}

			/// <summary>
			/// The SomeDivTag item.
			/// </summary>
			public virtual Ranorex.DivTag SomeDivTag
			{
				get
				{
					return _somedivtagInfo.CreateAdapter<Ranorex.DivTag>(true);
				}
			}

			/// <summary>
			/// The SomeDivTag item info.
			/// </summary>
			public virtual RepoItemInfo SomeDivTagInfo
			{
				get
				{
					return _somedivtagInfo;
				}
			}

			/// <summary>
			/// The Self item.
			/// </summary>
			public virtual Ranorex.WebDocument Self
			{
				get
				{
					return _selfInfo.CreateAdapter<Ranorex.WebDocument>(true);
				}
			}

			/// <summary>
			/// The Self item info.
			/// </summary>
			public virtual RepoItemInfo SelfInfo
			{
				get
				{
					return _selfInfo;
				}
			}
		}

		/// <summary>
		/// The ContainerSelectboxAppFolder folder.
		/// </summary>
		public partial class ContainerSelectboxAppFolder : RepoGenBaseFolder
		{
			private RepoItemInfo _listitem11334Info;
			private RepoItemInfo _listitem19295Info;
			private RepoItemInfo _listitem036000195583Info;
			private RepoItemInfo _listitem036000198409Info;
			private RepoItemInfo _selfInfo;

			/// <summary>
			/// Creates a new ContainerSelectbox  folder.
			/// </summary>
			public ContainerSelectboxAppFolder(RepoGenBaseFolder parentFolder) :
					base("ContainerSelectbox", "/container[@caption='selectbox']", null, 30000, true)
			{
				_listitem11334Info = new RepoItemInfo(this, "ListItem11334", "listitem[@accessiblename='11334']", 10000, null);
				_listitem19295Info = new RepoItemInfo(this, "ListItem19295", "listitem[@accessiblename='19295']", 10000, null);
				_listitem036000195583Info = new RepoItemInfo(this, "ListItem036000195583", "listitem[@accessiblename='036000195583']", 10000, null);
				_listitem036000198409Info = new RepoItemInfo(this, "ListItem036000198409", "listitem[@accessiblename='036000198409']", 10000, null);
				_selfInfo = new RepoItemInfo(this, "Self", "", 30000, null);
			}

			/// <summary>
			/// The ListItem11334 item.
			/// </summary>
			public virtual Ranorex.ListItem ListItem11334
			{
				get
				{
					return _listitem11334Info.CreateAdapter<Ranorex.ListItem>(true);
				}
			}

			/// <summary>
			/// The ListItem11334 item info.
			/// </summary>
			public virtual RepoItemInfo ListItem11334Info
			{
				get
				{
					return _listitem11334Info;
				}
			}

			/// <summary>
			/// The ListItem19295 item.
			/// </summary>
			public virtual Ranorex.ListItem ListItem19295
			{
				get
				{
					return _listitem19295Info.CreateAdapter<Ranorex.ListItem>(true);
				}
			}

			/// <summary>
			/// The ListItem19295 item info.
			/// </summary>
			public virtual RepoItemInfo ListItem19295Info
			{
				get
				{
					return _listitem19295Info;
				}
			}

			/// <summary>
			/// The ListItem036000195583 item.
			/// </summary>
			public virtual Ranorex.ListItem ListItem036000195583
			{
				get
				{
					return _listitem036000195583Info.CreateAdapter<Ranorex.ListItem>(true);
				}
			}

			/// <summary>
			/// The ListItem036000195583 item info.
			/// </summary>
			public virtual RepoItemInfo ListItem036000195583Info
			{
				get
				{
					return _listitem036000195583Info;
				}
			}

			/// <summary>
			/// The ListItem036000198409 item.
			/// </summary>
			public virtual Ranorex.ListItem ListItem036000198409
			{
				get
				{
					return _listitem036000198409Info.CreateAdapter<Ranorex.ListItem>(true);
				}
			}

			/// <summary>
			/// The ListItem036000198409 item info.
			/// </summary>
			public virtual RepoItemInfo ListItem036000198409Info
			{
				get
				{
					return _listitem036000198409Info;
				}
			}

			/// <summary>
			/// The Self item.
			/// </summary>
			public virtual Ranorex.Container Self
			{
				get
				{
					return _selfInfo.CreateAdapter<Ranorex.Container>(true);
				}
			}

			/// <summary>
			/// The Self item info.
			/// </summary>
			public virtual RepoItemInfo SelfInfo
			{
				get
				{
					return _selfInfo;
				}
			}
		}

	}
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: html select box

Post by Support Team » Wed Oct 20, 2010 11:45 am

Hi,

Thank you for posting the repository code, but please take a look to Alex's post
Support Team wrote:Did you try using the code generated by the recorder? What's the RanoreXPath of the repository item used by Ranorex Recorder?
We need the Recorder Code / User Code. Depends on how you execute it in your executable. Would it be possible to post it again and please attach it as file. As file it is much easier to read for us instead of posting it as plain text. Thank you.
Please also take a look to the second point of Alex's post
Support Team wrote:Could you post two Ranorex snapshots of the drop down: One when the drop down is closed and one when it's opened? (How to create a Ranorex Snapshot...)
To analyze your problem, it is much easier for us with a Ranorex Snapshot of your control. How to create a Ranorex Snapshot...

Thanks in advance.

Regards,
Peter
Ranorex Team

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Wed Oct 20, 2010 10:11 pm

Hi,
I've attached files as requested. I think I captured them correctly using the instructions posted.

I think this is the path used by the recorder.
/dom[@domain='192.168.245.138']body/form/div[3]/div[@id='middle']/div/div/div[@id='right']/div[1]/div/container[@caption='selectbox']

But if I use ranorex spy it evaluates to this:

/dom[@domain='192.168.245.138' and @caption='Searchandise Reportal' and @page='index.aspx' and @path='/index.aspx' and @browsername='IE']/body/form/div[3]/div[@id='middle']/div/div/div[@id='content']/div/div[1]/div/div[1]/select[@id='cphContent_ddlFilter']

Thanks!
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: html select box

Post by Support Team » Thu Oct 21, 2010 2:23 pm

Hi,

Thank you again for the repository code, but we need your code, where do you want to perform your actions with the combo box. Even better would be to send us your whole project. Then we can help you with the implementation of a method to open the combo-box and iterate the list items. You can post it to this topic or send it to [email protected]

I also looked at your snapshots and find out following:
  • First snapshot (open.rxsnp):
    We would need a snapshot of the container which will be generated when you open the combo-box. This is exactly that container which you can see in recording code. Following RxPath
    chunkylover53 wrote:/dom[@domain='192.168.245.138']body/form/div[3]/div[@id='middle']/div/div/div[@id='right']/div[1]/div/container[@caption='selectbox']
  • The seconds snapshot (closed.rxsnp):
    It is a standard combo box (not opened) in a web page. After you open the combo box you will get a container where your elements are nested. This is exactly that container you can see in recording code. Following RxPath
    chunkylover53 wrote:/dom[@domain='192.168.245.138']body/form/div[3]/div[@id='middle']/div/div/div[@id='right']/div[1]/div/container[@caption='selectbox']
Why is the RxPath of the Recording and Ranorex Spy different
Ranorex Recorder automatically took the correct objects to perform your automation actions. When you use Spy and press the track button, and mouse over the item to recognize the combo-box element, you will get the Web Element Select, because this item is nested in your DOM Object and therefore you get the Select element. But if you use Instant Tracking of Spy you will see the same container which is used in the recording. Therefore, please open Spy. Now open your combo-box. Move with your mouse over the list items and press on your keyboard "CTRL+WinKey". Now Spy has tracked the same container you can see in recording.
For instant tracking please take also a look to following link
http://www.ranorex.com/support/user-gui ... html#c1797

Regards,
Peter
Ranorex Team

chunkylover53
Posts: 23
Joined: Wed Oct 06, 2010 8:21 pm

Re: html select box

Post by chunkylover53 » Thu Oct 21, 2010 9:40 pm

Hi,
I've emailed you my project and attached two more snapshots.
I think I captured it correctly this time. If not let me know and I will repost.
Thank You
You do not have the required permissions to view the files attached to this post.