I select a value from a drop list and need to read the label. I can't get it work. Any help is appreciated.
WebElement stSelection = driver.findElement(By.id("ddlGlobalStoreNumber"));
Select stSelect = new Select(stSelection); // Create a select object from select class for dropdown selection
stSelect.selectByIndex(16);
System.out.println(stSelect.getOptions().get(16).getText());
This line containing System.out raise the error :
org.openqa.selenium.StaleElementReferenceException
Related
Hello I am trying to implement a drop down in asp.net. The drop down is being loaded from database and is being binded with drop down. The list has various values and text. But I want to add the first option of "Please Select" which is disabled for selection at the top of drop down list. Also on binding the drop down I want to point to the value which user had previously selected so that's why I am using selectedValue option. the problem is if I add the first item as "please select" from code behind at item 0 and selectedvalue to the value stored in db it still shows me item zero" please select".
DropDownList ddlMinEdit = (DropDownList)currentGrid.Rows
[currentGrid.EditIndex].FindControl("ddlMinEdit");
ddlMinEdit.Items.Insert(0, "Select Please");
ddlMinEdit.Items [0].Attributes.Add("disabled", "disabled");
ddlMinEdit.DataSource = CList;
ddlMinEdit.DataTextField = "empid";
ddlMinEdit.DataValueField = "empname";
ddlMinEdit.DataBind();
ddlMinEdit.SelectedValue = defemp;
So any suggestion how do I add first item and at same time bind a list and point to selected value. thanks
The order that you are doing things doesn't seems correct. You should insert the "Select Please" after the data binding and setting the selected value:
DropDownList ddlMRCClinEdit = (DropDownList)currentGrid.Rows [currentGrid.EditIndex].FindControl("ddlMRCClinEdit");
ddlMRCClinEdit.DataSource = clinList;
ddlMRCClinEdit.DataTextField = "empid";
ddlMRCClinEdit.DataValueField = "empname";
ddlMRCClinEdit.DataBind();
ddlMRCClinEdit.SelectedValue = defemp;
ddlMRCClinEdit.Items.Insert(0, "Select Please");
ddlMRCClinEdit.Items [0].Attributes.Add("disabled", "disabled");
I have a form view in ASP.NET with a text box and a drop down list.
I'm trying to populate the drop down list - from a separate table than the one I'm inserting data into. For example - a list of states - with Value = CA; Text = California.
I have a LINQ statement that I've created, but I can't seem to populate the ddl.
Any suggestions?
First of all return a list from your table:
myEntities dc = new myEntities();
List<MyTable> lst = (from ro in dc.MyTable select ro).ToList();
Than, add an object into your list (or insert into a position).
lst.Insert(0, new MyTable(){TextField = "California", ValueField = "CA"});
drp.DataSource = lst;
drp.DataBind();
I have a listbox in VB.NET that allows users to select multiple categories. I need to put these categories into a database and need the index value from the listbox of the categories as the database works off IDs. SelectedItems (with an s) does not work in the net application.
I have tried the following code:
For Each category As ListItem In CategoryListBox.Items
If category.Selected Then
Dim courseCategory As New CourseCategory
courseCategory.CourseID = course.ID
courseCategory.CategoryID = CategoryListBox.SelectedIndex
Using courseCategoryEntities As New Eng_NWDTrainingWebsiteEntities
courseCategoryEntities.CourseCategories.Add(courseCategory)
courseCategoryEntities.SaveChanges()
End Using
End If
Next
When iterating through the loop the code that is:
courseCategory.CategoryID = CategoryListBox.SelectedIndex
works correctly the first time around.
On the second iteration of the loop, it goes to the next selected item however returns the index for the first selected value. How do I return the values of the other indexes selected?
It depends on what ID you need to pass to your database. If it is truly the index of the ListItem in the ListBox, then you would use:
courseCategory.CategoryID = CategoryListBox.Items.IndexOf(category);
That may not be the best approach however. Maybe the order of the ListItems changes, messing up your indexes. You probably want to store the actual CategoryID on each ListItem. The Value property works well for that. You set the column you want as the DataValueField like so:
<asp:ListBox ID="CategoryListBox" runat="server"
DataValueField="CategoryID "></asp:ListBox>
So as you are looping through each ListItem in the ListBox and checking if it is selected, just use it's Value property.
For Each category As ListItem In CategoryListBox.Items
If category.Selected Then
Dim courseCategory As New CourseCategory
courseCategory.CourseID = course.ID
courseCategory.CategoryID = category.Value;
Using courseCategoryEntities As New Eng_NWDTrainingWebsiteEntities
courseCategoryEntities.CourseCategories.Add(courseCategory)
courseCategoryEntities.SaveChanges()
End Using
End If
Next
Fixed the code by deselecting the item in the listbox after it was successfully saved.
End Using
category.Selected = False
End If
This solved my problem.
I have been asked question on this scenario.There are 2 dropdownlist populating same data from same table one at top and other at bottom.when Item in first dropdownlist get selected,same item is shown in second dropdownlist and second item get selected,same item is selected in first.That means it is continuous loop.How to handle this situation. Don't want to use query
select name from table where id = ddl1.selecteditem.value and execute it.
On selectedindex function of dropdownlist1,he wrote like this
ddl2.selectedItem.value = ddl.selectedItem.value
and second list
ddl.selectedItem.value = ddl2.selectedItem.value
Does it possible to select the value from these 2 statement?I done like this,but not working.
In order to get the same value in both dropdownlists you need to do this in your dropdownlist1_selectedindexchanged:
DropDownList2.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
The same in dropdownlist2_selectedindexchanged:
DropDownList1.Items.FindByValue(DropDownList2.SelectedValue).Selected = true;
This should keep the same value in both dropdownlists whenever they have been modified.
Its like I have multiselect option in Jqgrid in which i want to pass the selected rows value to the server and based on the value i will delete the rows. I dont want to have the ids to do my work. For the Single row i get the cell value and delete using the same. But for multi select its not the case. In getGridParam('selarrrow'); I use this to fetch the selected rows bu the values are not getting populated. Please help me out in doing the same
When i use the following code as i saw in some sample question i can fetch the value for the single row selection but when i select multiple rows then i pass it says like "FALSE" or "UNDEFINED". What can be the issue. var grid = jQuery('#list'); var sel_id = grid.jqGrid('getGridParam', 'selarrrow'); var myCellData = grid.jqGrid('getCell', sel_id, 'CountryId');
I got this done by using the for loop for getting the selected rows id
i did some thing like this and I am able to fetch the value. Thought this might help others too please check it
var myrow;
var id = jQuery("#List").jqGrid('getGridParam','selarrrow');
if(id.length)
{
for (var i=0;i<id.length;i++) // For Multiple Delete of row
{
myrow = jQuery("#List").jqGrid('getCell',id[i],'ticker');
}
}