html select box : General Questions - Page 2

html select box

Ask general questions here.

Re: html select box

Postby chunkylover53 » Mon Oct 25, 2010 10:14 pm

Okay, here's the latest

By changing my click method from models.click() to models.click(new Location()) I can expand the drop down finally.
Now my code can get the list of items using your code: IList<Ranorex.ListItem> optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem");

So far so good.

However after the first iteration in the loop, it no longer selects the items in the drop down. Rather it goes to the browser tool bar and does a right click and opens the browser menu.

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

}
I suspect the problem is that when an item is selected in the drop down, the page does postback and the references get lost.
Any suggestions?

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

Re: html select box

Postby artur_gadomski » Tue Oct 26, 2010 8:04 am

Try:
-remember the size of the list first time you open it, keep a index counter and do a for loop:
//Open combobox 
models.Click(new Location());
List<Ranorex.ListItem> optionList = Host.Local.Find<Ranorex.ListItem("/container[@caption='selectbox']/listitem"); 
int listLength = optionList.Length;
for (int i = 0; i< listLenght; i++) {
    //Open combobox 
    models.Click(new Location());
    //Get list
    optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem"); 
    //Click list item 
    optionList[i].Click();
}

-you could also try while looping based on selected item index of combo box.
models.Click(new Location());
optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem"); 
optionList[0].Click();
bool goOn = true;
while (goOn) {
    //Open combobox 
    models.Click(new Location());
    //Get list
    optionList = Host.Local.Find<Ranorex.ListItem>("/container[@caption='selectbox']/listitem"); 
    if (models.SelectedItemIndex +1 > optionList.Length-1) {
        //Click list item 
        optionList[models.SelectedItemIndex +1].Click();
    } else {
        goOn = false;
    }
}
User avatar
artur_gadomski
 
Posts: 125
Joined: Mon Jul 19, 2010 7:55 am
Location: Copenhagen, Denmark

Re: html select box

Postby chunkylover53 » Wed Oct 27, 2010 11:46 pm

Thanks, that code worked.
chunkylover53
 
Posts: 23
Joined: Wed Oct 06, 2010 9:21 pm

Re: html select box

Postby dal » Thu Oct 28, 2010 2:56 pm

Hi,

I have used the following two ways of selecting the appropriate listBox item....

Can you give a try...

Method - 1
Imports Ranorex
Imports Ranorex.Core
Imports Microsoft.VisualBasic
Imports System

'Variable Declaration
Dim rxPath As String = ""
Dim item As Ranorex.ListItem = Nothing
Dim isFound As Boolean = False

'Creating instances for Global Repositories
Dim TestRepo As GlobalRepository = GlobalRepository.Instance
TestRepo.ObjListBoxName.Focus 'List Box/Combo Box Object
TestRepo.ObjListBoxName.Click 'List Box/Combo Box Object
	
rxPath = String.Format(".//listitem[@accessiblename='{0}']", “ItemToBeSelected")
	
'Searching for list item based on the created RanorexXPath
isFound = TestRepo.ContainerListBox.Self.TryFindSingle(rxPath, item)
								
If isFound Then
item.[Select]()
	item.Click()
Else
	Report.Warn("ListBox Item Not Found")
End If


Method - 2
Imports Ranorex
Imports Ranorex.Core
Imports Microsoft.VisualBasic
Imports System

'Creating instances for Global Repositories
Dim TestRepo As GlobalRepository = GlobalRepository.Instance
TestRepo.ObjListBoxName.Focus 'List Box/Combo Box Object
TestRepo.ObjListBoxName.Click 'List Box/Combo Box Object

For Each [option] As OptionTag In TestRepo.ObjListBoxName.Find(".//option[@innerText='ItemToBeSelected']")

[Option]("selected") = "selected"
[option].Click
Next
dal
 
Posts: 72
Joined: Thu Jun 24, 2010 9:59 am

Previous

Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests

cron