I am using Ranorex 3.1 and C#. I am using IE 9.
The web site I am testing has a Drop Down (Select List) and I need to change the value of this during my test runs. I really feel like I am missing something because this has not been easy. I don't care if I accomplish this via the record module or user code. When I do record it clicks the asset that is behind the list when it is "dropped down". I just want a "set" option available for this asset. It's very frustrating.
Any ideas?
Selecting Option in a Select List (Drop Down List)
Selecting Option in a Select List (Drop Down List)
You do not have the required permissions to view the files attached to this post.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Selecting Option in a Select List (Drop Down List)
Hi,
To select a specific option tag in your select tag you could use following code
The code above works in both browsers (IE and Firefox).
Regards,
Peter
Ranorex Team
To select a specific option tag in your select tag you could use following code
SelectTag someSelectTag = "/dom[@domain='www.w3schools.com']/body/table[2]/tbody/tr[1]/td[2]/iframe/body/select"; OptionTag optTag = someSelectTag.FindSingle(".//option[@value='Volvo']"); optTag.Selected = true;The sample page is http://www.w3schools.com/tags/tryit.asp ... tml_option
The code above works in both browsers (IE and Firefox).
Regards,
Peter
Ranorex Team
Re: Selecting Option in a Select List (Drop Down List)
That did work, I see the select box change values, unfortunately it didn't fire off the code that is suppose to be called when the drop down is changed. If you have any other suggestions let me know, otherwise I will just have to use the first letters and Up and Down Arrow to navigate it.
Re: Selecting Option in a Select List (Drop Down List)
Try this method:
Code: Select all
public static int DOMComboSelect(Ranorex.WebDocument webDocumentName, string ComboName, string ComboItem)
{
/************************************************************************
* Function : DOMComboSelect(Ranorex.WebDocument webDocumentName, string ComboName, string ComboItem)
*
* Description : This method will select a ComboBox item in a web document.
*
* Parameters : webDocumentName - The web DOM object the the ComboBox lives on
* : ComboName - Name of the ComboBox to click
* : ComboItem - Item in the ComboBox to select.
*
* Return Type : Integer
*
* Return Value : 0 for success, -1 for failure
*
* Revision History
* Date : Author : Reason/Change
* ---------- : ------------------------- : ------------------------------
* 03/10/2009 : Chris Gendreau : Initial Creation
************************************************************************/
Ranorex.SelectTag DOMCombo;
//Search for the ComboBox on the page
try
{
webDocumentName.EnsureVisible();
Thread.Sleep(500);
DOMCombo = webDocumentName.FindSingle(".//select[@Id='" + ComboName + "']");
}
catch (RanorexException e)
{
Report.Error("Unable to find ComboBox: " + ComboName);
Console.WriteLine(e.ToString());
Report.Screenshot();
return -1;
}
//Verify Item exists in ComboBox
int intResult = DOMComboVerifyItem(webDocumentName, ComboName, ComboItem);
if (intResult == -1)
{
Report.Error("Item: " + ComboItem + " is not a valid item in the ComboBox: " + ComboName);
return -1;
}
//Click a ComboBox & Item
try
{
Report.Info("Selecting item: " + ComboItem + " in ComboBox: " + ComboName);
DOMCombo.EnsureVisible();
DOMCombo.Focus();
Thread.Sleep(1000);
DOMCombo.Click(Location.CenterRight, 1000);
Thread.Sleep(1000);
ListItem item = "/container[@caption='selectbox']/listitem[@text='" + ComboItem + "']";
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;
} //End DOMComboSelect
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...
Ciege...
Re: Selecting Option in a Select List (Drop Down List)
Hi - I am having the same problem as Pixi6s above... if I use the following code, the code that is supposed to fire on dropdown selection change does not execute:
If I remove the 'option.Selected' property as detailed below, the dropdown change action executes properly, but if the list item is out of view and requires scrolling, the wrong ListItem is selected.
Hope you can help with this.
Thanks,
Natasha
Code: Select all
ListItem item = "/container[@caption='selectbox']/listitem[@text='" + name + "']";
OptionTag option = dropDown.FindSingle(".//option[@innertext='"+ name +"']");
option.Selected = true;
item.Click();
If I remove the 'option.Selected' property as detailed below, the dropdown change action executes properly, but if the list item is out of view and requires scrolling, the wrong ListItem is selected.
Code: Select all
ListItem item = "/container[@caption='selectbox']/listitem[@text='" + name + "']";
OptionTag option = dropDown.FindSingle(".//option[@innertext='"+ name +"']");
//option.Selected = true;
item.Click();
Hope you can help with this.
Thanks,
Natasha
Re: Selecting Option in a Select List (Drop Down List)
you can use the below function which we created for our purpose.
Find_str is the string which need to be found and office_path is the object for the selectTag.
Public Function fnDropDown_FindOption(ByVal Find_str As String, ByVal office_path As Ranorex.SelectTag) As Boolean
fnDropDown_FindOption = False
Try
Dim optag_office As System.Collections.Generic.IList(Of OptionTag) = office_path.Find(Of Ranorex.OptionTag)("./option")
For c As Integer = 1 To optag_office.Count
Dim opt_office_rxpath As New RxPath("./option[" + c.ToString + "]")
Dim office_opt_port As Ranorex.OptionTag = office_path.FindSingle(Of Ranorex.OptionTag)(opt_office_rxpath)
Dim offname As String = office_opt_port.InnerText.Trim
If offname.ToLower = Find_str.ToLower.Trim Then
office_path.EnsureVisible()
office_path.Click()
optag_office(c - 1).Selected = True
optag_office(c - 1).PerformClick()
office_path.Click()
fnDropDown_FindOption=True
Exit For
End If
Next
Catch ex As RanorexException
MsgBox(ex.ToString)
End Try
End Function
This Function will return True if the required was selected else it will return False
Find_str is the string which need to be found and office_path is the object for the selectTag.
Public Function fnDropDown_FindOption(ByVal Find_str As String, ByVal office_path As Ranorex.SelectTag) As Boolean
fnDropDown_FindOption = False
Try
Dim optag_office As System.Collections.Generic.IList(Of OptionTag) = office_path.Find(Of Ranorex.OptionTag)("./option")
For c As Integer = 1 To optag_office.Count
Dim opt_office_rxpath As New RxPath("./option[" + c.ToString + "]")
Dim office_opt_port As Ranorex.OptionTag = office_path.FindSingle(Of Ranorex.OptionTag)(opt_office_rxpath)
Dim offname As String = office_opt_port.InnerText.Trim
If offname.ToLower = Find_str.ToLower.Trim Then
office_path.EnsureVisible()
office_path.Click()
optag_office(c - 1).Selected = True
optag_office(c - 1).PerformClick()
office_path.Click()
fnDropDown_FindOption=True
Exit For
End If
Next
Catch ex As RanorexException
MsgBox(ex.ToString)
End Try
End Function
This Function will return True if the required was selected else it will return False
Re: Selecting Option in a Select List (Drop Down List)
How to select 1st item from the list box since items are dynamically changed.
Thank you,
Thank you,
Tipu
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Selecting Option in a Select List (Drop Down List)
Hello,
You could use 'first()=true' to get the first item from a list.
Please take a look at our User Guide for more information:
http://www.ranorex.com/support/user-gui ... xpath.html
Regards,
Markus (T)
You could use 'first()=true' to get the first item from a list.
Please take a look at our User Guide for more information:
http://www.ranorex.com/support/user-gui ... xpath.html
Regards,
Markus (T)