html select box

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

Re: html select box

Post by chunkylover53 » Mon Oct 25, 2010 9: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

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: html select box

Post by artur_gadomski » Tue Oct 26, 2010 7: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.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;
    }
}

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

Re: html select box

Post by chunkylover53 » Wed Oct 27, 2010 10:46 pm

Thanks, that code worked.

dal
Posts: 72
Joined: Thu Jun 24, 2010 8:59 am

Re: html select box

Post by dal » Thu Oct 28, 2010 1: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

macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Re: html select box

Post by macgowan » Thu Jan 15, 2015 7:54 pm

Hi ...

I was following along on this discussion ...

We used some input in this discussion form our solution.

We had some issues using the UI and Ranorex to access a dropdown menu on an html page. Typically when setting the xpath (RanorexPath) for web elements that we want to interact with - we will expose the elements on the application and then use the Track feature in the Ranorex Repository or the Spy Tool to get the xpath.

Using the Track feature in the Ranorex Repository was difficult as the dropdown menu will close when the Track button is pressed. We looked at setting the xpath using the Spy Tool - we were able to get a valid xpath but it did not behave as expected - selecting the menu option?

It was then I started to look at using the DOM to access the dropdown menu.

With the RanoreXPath using the native adapter failing - we have implemented a solution that will access the DOM and iterate the dropdown menu options and operate on them.

The user will pass the xpath of the dropdown control, the container where the menu items are located and the index of the selected item. The dropdownXPath is used to get the dropdown SelectTag object. The containerXPath is used to get the container of menu items that are loaded into a ListItem collection object. The menuListItemIndex is used to get the menuItem from the ListItem collection. The SelectTag object is used to open the dropdown control. The menuItem is used to operate on the menu item - in this case Click().

Below is the call to SelectDropdownMenuItem() and the implementation below ...

Code: Select all

// Set the xpath and menu index to select sysnopsis from create new menu
dropdownXPath = ".//div[@id~'[0-9]*_judicialsummary.trialCourtOrderSummaryPage.section.widget.contentViewerWindow']/div[1]/div/div/a[6]/?/?/select";

containerXPath = "/container[@caption='selectbox']/listitem"; 
menuListItemIndex = 2; 

// Access the DOM to operate on the dropdown menu                    
ContentHelper.SelectDropdownMenuItem(dropdownXPath, 
                                     containerXPath, 
                                     menuListItemIndex); 



public static void SelectDropdownMenuItem(string dropdownXPath, 
                                          string containerXPath, 
                                          int menuListItemIndex)
{
    string domDefinition; 

    try
    { 
        Report.Info("Operate on the dropdown menu using the DOM and xpath");

        Report.Debug("Set dom definition for current environemnt. Environment=" + SummaryBase.Environment);
        domDefinition = "/dom[@domain='" + SummaryBase.Environment + ".workbench.judicial.int.private.domain.com']"; 

        Report.Debug("Create the Ranorex.WebDocument object and set it with the domDefinition");
        Report.Debug("domDefinition: " + domDefinition);

        // Create the WebDocument object and set the DOM string             
        Ranorex.WebDocument webDoc = domDefinition;

        Report.Debug("Using webDoc.FindSingle() to get the select tag");
        SelectTag selectTagS = webDoc.FindSingle(dropdownXPath);  

        Report.Debug("selectTagS: " + selectTagS.ToString());

        Report.Debug("Open Combobox to get the container");
        selectTagS.Click();   

        Report.Debug("Searching for the container containg the list items");
        IList<Ranorex.ListItem> optionList = Host.Local.Find<Ranorex.ListItem>(containerXPath);  

        // This is for debug purpose only                     
        Report.Debug("Ranorex.ListItem optionList count: " + optionList.Count);
        Report.Debug("Iterate the collection");
        foreach(ListItem listItem in optionList)  
        {  
            Report.Debug("listItem object [index]: " + listItem.ToString() + "[" + listItem.Index + "]");
        }                      
       
        Report.Info("Close (reset) dropdown");
        selectTagS.Click();   

        Report.Debug("Get the ListItem object using the index");
        ListItem menuListItem = optionList[menuListItemIndex]; 
        Report.Debug("menuListItem:  " + menuListItem.ToString());

        Report.Info("Click on the dropdown to open the menu");
        selectTagS.Click();  

        Report.Info("Select menuListItem from dropdown menu");
        menuListItem.Click();  

    } 
    catch(Exception exception) 
    { 
        throw exception; 
    }       
}

Thanks,
Chris

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: html select box

Post by krstcs » Thu Jan 15, 2015 8:12 pm

Chris,

You can track menu/drop-down items by using either of the following options:

1. Press the "Ctrl-LWin" key combination ("Instant Tracking") while the mouse is over the desired object.

2. Click the "Track" button like you were doing and the press and hold "F12" ("Override") until you get the menu/drop-down open to where you want it. Then release "F12" and click the object you want to track.


As far as operating on drop-down select tag elements in different browsers, I have had more luck with using keyboard-up/down keys than using the mouse because each browser implements the drop-down slightly differently so you won't be able to get a consistent XPath to the list items.
Shortcuts usually aren't...

Celine079
Posts: 1
Joined: Fri Jan 16, 2015 5:30 am

Re: html select box

Post by Celine079 » Fri Jan 16, 2015 6:58 am

OK,thanks for these infos !!!

allensmith
Posts: 1
Joined: Tue Jan 20, 2015 7:31 am

Re: html select box

Post by allensmith » Fri Jan 23, 2015 3:36 am

I learn a lot from you guys.