Bootstrap select dropdown not rendering viewbag items - asp.net-core

For some reason my list is showing up disabled I am trying to use bootstrap-select here
https://developer.snapappointments.com/bootstrap-select/
This is my code that gets the items there is nothing wrong with it as 3 items exist in the view bag
public void GetStandardLookups(int LookupGroupId) {
List<SelectListItem> listItems = new List<SelectListItem>();
var items = _context.StandardLookups.Where(w => w.LookupGroup == LookupGroupId).ToList();
foreach (var item in items) {
SelectListItem listItem = new SelectListItem();
listItem.Text = item.LookupText;
listItem.Value = item.Id.ToString();
listItems.Add(listItem);
}
if(LookupGroupId == Constants.EnforcmentType)
ViewBag.EnforceMentTypesList = listItems;
if (LookupGroupId == Constants.EnforcmentCategory)
ViewBag.EnforcmentCategoryList = listItems;
}
I Create the dropdown as such after storing in the view bag on the controller action of edit. But when I look at the raw html all i have is. This is three rows of data in the database that should be pulling through and I debugged my code and it is getting three items in list Items.
Nothing selected
I am initializing my bootstrap select as follows
$(function () {
$('.selectpicker').selectpicker();
})
I am producing my drop down as follows.
#Html.DropDownListFor(x => x.Enf_Type, (IEnumerable<SelectListItem>)ViewBag.EnforceMentTypesList, String.Empty, new { #class = "selectpicker form-control" })
My Edit action

I did a test using same bootstrap-select you share with testing data, which work as expected.
its shows the words nothing to select and is disabled non clickable
Please check if the html source of dropdown-toggle button with CSS class 'disabled' like below.
<button type="button" class="btn dropdown-toggle disabled btn-light bs-placeholder" data-toggle="dropdown" role="combobox" aria-owns="bs-select-1" aria-haspopup="listbox" aria-expanded="false" data-id="Enf_Type" tabindex="-1" aria-disabled="true" title="Nothing selected"><div class="filter-option"><div class="filter-option-inner"><div class="filter-option-inner-inner">Nothing selected</div></div> </div></button>
And if rendered <select> element with disabled attribute.
<select class="selectpicker form-control" data-val="true" data-val-required="The Enf_Type field is required." disabled="disabled" id="Enf_Type" name="Enf_Type" tabindex="-98"><option value="">
You can try to programmatically enable a selectpicker with following code snippet.
$('.selectpicker').prop('disabled', false);
$('.selectpicker').selectpicker('refresh');

Related

Send List of IDs from List of Object From View to Controller C#

I have a view with a list of objects as its model
#model List<Users>
Inside that view, I have a form and button to submit the form in ASP.NET Core MVC:
<input class="btn btn-success ml-2" style=" width: 100px;"
type="submit" value="#localizer["Save"]" />
I need another button to cancel form submission and redirect to another method but I need to pass the list of Users with redirection at cancel button
I tried
<a asp-controller="User" asp-action="cancel" asp-route-ids="#Model.Select(x => x.id);">Cancel</a>
but it didn't work, the list is empty
If you use asp-route-somekey to set the query, your target list name was recognized as value of the key "Ids",you could see the result as below:
If you do want to pass list to the query,you could try:
<a asp-controller="User" asp-action="Cancel" asp-all-route-data="#(new Dictionary<string, string> { { "Ids[0]", "1" },{ "Ids[1]", "2" } })">Cancel</a>
The result:
However the length of url is limited, it may cause some errors

Locater strategy give two results in selenium ide

For all the checkboxes and radio buttons i create a locater builder:
LocatorBuilders.add('radio', function(e) {
var name = e.parentNode.parentNode.getAttribute('name');
var value = name + '_' + e.parentElement.getAttribute('value');
var result = 'radio=' + value;
return result;
});
And a locater strategy:
PageBot.prototype.locateElementByRadio = function(locatorString, inDocument, inWindow) {
var name = locatorString.split('_')[0];
var value = locatorString.split('_')[1];
var result = inDocument.querySelector('div[field=' + name +'] label[value=' + value +'] input');
return result;
}
HTML element:
<div class="radio" name="radio-example" style="">
<label class="radio-label" value="male" style="">
<input class="radio-input" style="" tabindex="1" type="radio">
<span class="option">Man</span>
</label>
</div>
This works perfect and in my selenium IDE is ee something like radio=new_yes
But when i record a click on a radio i see two commands in selenium ide. One command with the locater builder and one command with a verry long xpath that belong to the label from the checkbox. How can i record only the input field from the checkbox? and not the label ?
If you are only trying to get the locator for the radiobutton, you can use this locator
css=input.radio-input
Let me know if you have any more questions.

How to deal with checkbox using selenium webdriver?

i want to scrape a page with checkboxes with no id, they have the same name and just the values are differents.
<div class="mvNavLk">
<form class="jsExpSCCategories" method="post" name="ExpressSCCategories" action="actionTest.html">
<ul class="mvSrcLk">
<li>
<label class="mvNavSel mvNavLvl1">
First
<input type="checkbox" value="firstValue" name="selectedNavigationCategoryPath">
</label>
</li>
<li>
<label class="mvNavSel mvNavLvl1">
Second
<input type="checkbox" value="secondValue" name="selectedNavigationCategoryPath">
</label>
</li>
</ul>
</form>
</div>
use below code:
driver.find_element_by_css_selector(".mvSrcLk>li:nth-child(1)>label.mvNavSel.mvNavLvl1").click();
hope this will work.
Hope this works-
driver.FindElement(By.XPath(".//label[contains(text(),'First')]/input")).SendKeys("test");
Hi please do it like below Note this example is in java
// take check boxes with same name inside the list
List<WebElement> myCheckBox = driver.findElements(By.name("selectedNavigationCategoryPath"));
// now on the basis of index call click
myCheckBox.get(0).click(); // for the first check box
Thread.sleep(2000);
myCheckBox.get(1).click(); // for the second check box
or if you want to select on the basis of value then
driver.findElement(By.xpath("//*[#value='firstValue']")).click(); // for the 1st one
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#value='secondValue']")).click(); // for the 2st one
UPDATE
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#value='firstValue']")));
driver.findElement(By.xpath("//*[#value='firstValue']")).click(); // for the 1st one
Hope this helps you
driver.findElement(By.name("selectedNavigationCategoryPath")).click();
Below Code is in C#, Collects all the Checkboxes with the name specified. Then Iterates through each ckeckbox, gets the value attribute, if the attribute is equal to your specified check box, then clicks it and comes out of the loop. Hope this should work.
IList<IWebElement> myCheckBoxs = driver.FindElements(By.name("selectedNavigationCategoryPath"));
Foreach(IWebElement chkBx in myCheckBoxs)
{
if(chkBx.GetAttribute("Value")=="Your Desired value")
{
chkBx.Click();
break;
}
}
`
Use this CSS locator.
[name='selectedNavigationCategoryPath'][value='firstValue']

I am facing an issue in retrieving all the list items using selenium webdriver

Problem : I have a list of items inside a div class msb-container.
.There are 162 items in the list .I want to click the 150th item from the list .There also a scroll bar through which we can go doen to other elemenst and select it
How the html looks like :
<div class="mCSB_container" style="position:relative; top:0;">
<ul id="ul-countries">
<li>
<input id="country-3" type="checkbox" name="c:3">
<label for="country-3">Afghanistan</label>
</li>
<li>
<input id="country-6" type="checkbox" name="c:6">
<label for="country-6">Albania</label>
</li>
---other countries
</li>
</ul>
</div>
How my code looks like :
IList<IWebElement> countryList = driver.FindElements(By.XPath("//*[#id='ul-countries']/li"));
for (int i = 0; i <= countryList.Count; i++)
{
string temp = countryList.ElementAt(i).Text;
if (countryList.ElementAt(i).Text == "Brazil")
{
//do something
}
}
I am getting a correct count of 162 countries but i think they are not filled correctly .As when I try to retrieve the text from even the 15th country it gives me empty result .It only fills the text for those list item which can be seen on the screen .Although when I inspect element I can see all the required data in list item through html but not through my code .I tried to put the sleep to but no luck .
Please provide your inputs to solve the above issue.
|
Kindest Regards
IList<IWebElement> countryList = driver.FindElements(By.XPath("//*[#id='ul-countries']/li"));
for (int i = 0; i <= countryList.Count; i++)
{
string temp = countryList.ElementAt(i).findElement(By.CSS("label")).getText();
if (temp.equals("Brazil"))
{
//do something
}
}

Handle button action in a list

I am trying to develop an iphone application using sencha framework .I need to show a list of items in a list.Each cell in the list holds a button also.If the user clicks on a button in a particular index, then a popover needs to be displayer near to the button .I am using the following code to do this
itemTpl : '<div class="div1"><label class = "tag-name-hdr"> {tagnamehdr} </label> <label class = "tag-name-value" style="width:55px;"> value </label> <input type="text" class ="tag-name-text" name="lname" /> <label class = "unit-name" > unit </label> <select class = "unit-name_dropdown" > <option>mg/dr</option> <option>gm/dr</option> <option>m/dr</option> </select> <input type="image" id="popupbtn" class="template_popup_button" src="Images/arrow_more_orange.png" > </div>',
listeners : {
//itemtap : function(list, index, item, e, popupbtn) {
itemtap : function(list, index, item, evt) {
if(evt.getTarget('.template_popup_button')) {
alert(item);
alert(index);
showOverlay(item, evt, index);
}
}
}
Now my issue is that the popover is showing for the selected cell.I need to show the popover near to the clicked button.Is there any way to get the clicked button object to show the overlay/popover near to that.Now I am passing clicked item cell object as parameter to "showOverlay",i need to pass clicked button object
Thanks in advance..
The evt variable holds information about the event. You could check if evt.target is a button (or the button you want to act upon).
Note that if all you want is a single button per cell, you could use the onItemDisclosure config option, that will add a button for you with a handler.