I have a modal, within that modal there are various card. Those cards have dropdown. It looks some what like the screenshot below. They all have different select name. Is there any way to write a method in C# so I dont have to do //select[#name='test1a']or //select[#name='test1b'] for all dropdown?
HTML Code below
<table class="row-inner-table" border="0" cellpadding="1" cellspacing="1">
<tbody>
<tr class="row-content">
<td class="field-name">test1a</td>
<td class="field-value">
<select name="test-4" onchange="calc(document.myForm.TOTAL_8,this,24)">
<option value="" score="0"> </option>
<option value="118" score="0">test1b </option>
<option value="124" score="1">test1c</option>
<option value="120" score="2">test1d</option>
</select>
<input type="HIDDEN" name="PREVIOUS_24" value="0">
</td>
</tr>
<tr class="row-content">
<td class="field-name">test2</td>
<td class="field-value">
<select name="test-5" onchange="calc(document.myForm.TOTAL_8,this,25)">
<option value="" score="0"> </option>
<option value="121" score="0">hi</option>
<option value="113" score="1">hello</option>
<option value="114" score="2">C ya </option>
</select>
<input type="HIDDEN" name="PREVIOUS_25" value="0">
</td>
</tr>
<tr class="row-content">
<td class="field-name">test 3</td>
<td class="field-value">
<select name="test-6" onchange="calc(document.myForm.TOTAL_8,this,26)">
<option value="" score="0"> </option>
<option value="123" score="0">hehe</option>
<option value="112" score="1">haha</option>
<option value="119" score="2">001</option>
</select>
<input type="HIDDEN" name="PREVIOUS_26" value="0">
</td>
</tr>
<tr class="row-content">
<td class="field-name">test4</td>
<td class="field-value">
<select name="test-7" onchange="calc(document.myForm.TOTAL_8,this,27)">
<option value="" score="0"> </option>
<option value="111" score="0">404</option>
<option value="122" score="1">402/option>
<option value="117" score="2">403</option>
</select>
<input type="HIDDEN" name="PREVIOUS_27" value="0">
</td>
</tr>
<tr class="row-content">
<td class="field-name">test 5 </td>
<td class="field-value">
<select name="test-8" onchange="calc(document.myForm.TOTAL_8,this,28)">
<option value="" score="0"> </option>
<option value="115" score="0">Relaxed</option>
<option value="125" score="1">Tense, rigid</option>
<option value="116" score="2">Very tense or rigid</option>
</select>
<input type="HIDDEN" name="PREVIOUS_28" value="0">
</td>
</tr>
<tr class="row-content-total">
<td class="field-name total-label">Total</td>
<td class="field-value">
<input type="TEXT" size="5" name="TOTAL_8" value="0">
</td>
</tr>
</tbody>
</table>
It should be as easy as something like this
public SelectElement dropdownElement(By locator)
{
return new SelectElement(driver.FindElement(locator));
}
and you call it like
SelectElement select = dropdownElement(By.CssSelector("select[name='test-5']"));
Here is another version of C.Peck's solution which will cut down the repetitive Xpath (or CSS) string code, assuming the base of the Xpath is always the same which in the OP it appears to be
public SelectElement SelectMenuItem(string menuValue)
{
var menuString = $"//select[#name='{menuValue}']";
return new SelectElement(driver.FindElement(By.XPath(menuString)));
}
SelectElement selectOne = SelectMenuItem("test-4");
SelectElement selectTwo = SelectMenuItem("test-5");
EDIT:
To show you the A-Z on reusability for this, it would look something like this...
Method to return Select Element with dynamic XPath string:
public SelectElement SelectMenuItem(string menuValue)
{
var menuString = $"//select[#name='{menuValue}']";
return new SelectElement(_driver.FindElement(By.XPath(menuString)));
}
Method to set value for dropdown, by XPath:
public void SetMenuValue(string menuValue, string menuDropDown)
{
SelectElement select = SelectMenuItem(menuDropDown);
select.SelectByText(menuValue);
}
Finally, method to set the specific values you want, passing in value first, then XPath next:
public void Input_Values()
{
SetMenuValue("118", "test-4");
SetMenuValue("121", "test-5");
}
You don't need that last method, you could call SetMenuValue from anywhere, that was just another example of how you could do this
Related
When user selects value from dropdown list, the selected value is not shown after page reload. Only "All" is shown as selected. If I give an attribute in the as :
<option value="#trChannel.TrCode" selected = "#trChannel.TradeChanelDisplayText">#trChannel.TradeChanelDisplayText</option>
The value All is never shown as selected and when page is loaded the last option from list is shown. How can I fix this?
<section>
<table id="filters">
<tr>
<td style="width:180px">
<span class="snsSmallTextBold">Filter by Trade Channel: </span>
</td>
<td>
<select name="TradeChannelCode" style="width:200px" id="selectedTradeChannel">
<option value="" id="all">All</option>
#foreach (var trChannel in Model.FilterableTrChannels)
{
<option value="#trChannel.TrCode">#trChannel.TradeChanelDisplayText</option>
}
</select>
</td>
<td>
<div>
<button id="addTrChannel" style="background-color:white">Add Trade Channel</button>
</div>
</td>
<td style="width:410px"></td>
<td style="width:210px; float:right">
<span class="snsSmallTextBold">Filter by Subtrade Channel: </span>
</td>
<td>
<select name="SubtradeChannelCode" style="width:200px" id="selectedSubtradeChannel">
<option value="">All</option>
#foreach (var subtrChannel in Model.FilterableSubTrChannels)
{
<option value="#subtrChannel.SubTrCode">#subtrChannel.SubtradeChanelDisplayText</option>
}
</select>
</td>
<td>
<button id="addSubtrchannel" style="background-color:white">Add Subtrade channel</button>
</td>
</tr>
</table>
</section>
<script type="text/javascript">
$(document).ready(function () {
$("#filters select").change(function () {
load();
});
});
function load() {
var url = window.location.href.split('?')[0];
url = url + '?TradeChannelCode=' + $("#selectedTradeChannel").val() + '&SubtradeChannelCode=' + $("#selectedSubtradeChannel").val();
window.location.href = url;
}
</script>
I have a c# destktop application. In my database i have the names for some companies. My problem is that not all the names are written correctly so i need something to check the company name. I have found online platforms for checking name and CUI company, but i dont know how to integrate in my application. Could you help me, please?
UPDATE:
<form name="codfiscalForm" method="POST" action="/numeCod.html">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="text3">
<tbody><tr>
<td width="33%">
Judetul:
<!--webbot bot="Validation" s-display-name="cod" s-data-type="Number" s-number-separators="x," b-value-required="TRUE" i-minimum-length="1" i-maximum-length="10" s-validation-constraint="Greater than or equal to" s-validation-value="1" s-validation-constraint="Less than or equal to" s-validation-value="9999999999" -->
<select name="judet" size="1" class="form2">
<option value="40">BUCURESTI</option>
<option value="01">ALBA</option>
<option value="02">ARAD</option>
<option value="03">ARGES</option>
<option value="04">BACAU</option>
<option value="05">BIHOR</option>
<option value="06">BISTRITA-NASAUD</option>
<option value="07">BOTOSANI</option>
<option value="08">BRASOV</option>
<option value="09">BRAILA</option>
<option value="10">BUZAU</option>
<option value="11">CARAS-SEVERIN</option>
<option value="13">CONSTANTA</option>
<option value="51">CALARASI</option>
<option value="14">COVASNA</option>
<option value="12">CLUJ</option>
<option value="15">DIMBOVITA</option>
<option value="16">DOLJ</option>
<option value="17">GALATI</option>
<option value="52">GIURGIU</option>
<option value="18">GORJ</option>
<option value="19">HARGHITA</option>
<option value="20">HUNEDOARA</option>
<option value="21">IALOMITA</option>
<option value="23">ILFOV</option>
<option value="22">IASI</option>
<option value="24">MARAMURES</option>
<option value="25">MEHEDINTI</option>
<option value="26">MURES</option>
<option value="27">NEAMT</option>
<option value="28">OLT</option>
<option value="29">PRAHOVA</option>
<option value="30">SATU MARE</option>
<option value="31">SALAJ</option>
<option value="32">SIBIU</option>
<option value="33">SUCEAVA</option>
<option value="34">TELEORMAN</option>
<option value="35">TIMIS</option>
<option value="36">TULCEA</option>
<option value="37">VASLUI</option>
<option value="38">VALCEA</option>
<option value="39">VRANCEA</option>
</select>
</td>
<td width="29%">Numele:
<!--webbot bot="Validation" s-display-name="nume" s-data-type="String" b-allow-letters="TRUE" b-allow-digits="TRUE" b-allow-whitespace="TRUE" s-allow-other-chars=". , ? " "" b-value-required="TRUE" i-minimum-length="2" -->
<input name="name" type="text" class="form2" size="15">
</td>
<td width="38%"><input name="submit" type="submit" class="form1" value="VIZUALIZARE"></td>
</tr>
<tr>
<td width="33%">
</td>
<td width="29%"> </td>
<td width="38%"> </td>
</tr>
<tr>
<td width="33%">
</td>
<td width="67%" colspan="2"></td>
</tr>
</tbody></table>
</form>
For example, i have this form for a post method. There are 2 inputs, one for company adress and one for company name. By clicking the button "vizualizeaza", it returns me companies after name. How can i integrate this in my desktop application
<td >Club City</td>
<td > <input style="width: 98%" id="SnapI_txtCity" title="* Club City" class="boxStyle" onclick="" onchange="" maxlength="50"> </td>
<td>Sprinkler system present in club</td>
<td > <select id="SnapII_ddlSprinklerSys" title="* Please select Sprinkler system present in club " onclick="" onchange="">
<option selected="" value="SEL">Select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<tr>
<td style="text-align: right">
<img id="imgNext" onclick="ShowDiv('N')" name="imgNext" src="../_gfx/next.gif" runat="server"></td>
</tr>
Upto select button tab index is working,after select it is circulating from first.How i will solve it in asp.net?without adding tabindex it works upto last textbox.but it doesot goes to next image.
$(document).ready(function () {
$("input,select,img").each(function (i) { $(this).attr('tabindex', i + 1); });
});
I have a post that has an array of items coming in that have no int for keys but a string for a key. for example: (from post)
-----------------------------3805226668837
Content-Disposition: form-data; name="pool[Abelson_2834.jpg]"
general_pool
-----------------------------3805226668837
Content-Disposition: form-data; name="pool_place[Abelson_2834.jpg]"
1
-----------------------------3805226668837
Content-Disposition: form-data; name="mediatype[Abelson_2834.jpg]"
3
-----------------------------3805226668837
Content-Disposition: form-data; name="pool[Abelson_2852.jpg]"
general_pool
-----------------------------3805226668837
Content-Disposition: form-data; name="pool_place[Abelson_2852.jpg]"
1
-----------------------------3805226668837
Content-Disposition: form-data; name="mediatype[Abelson_2852.jpg]"
3
-----------------------------3805226668837
Content-Disposition: form-data; name="pool[Abelson_3160-1.jpg]"
general_pool
-----------------------------3805226668837
Content-Disposition: form-data; name="pool_place[Abelson_3160-1.jpg]"
1
-----------------------------3805226668837
Content-Disposition: form-data; name="mediatype[Abelson_3160-1.jpg]"
3
-----------------------------3805226668837
Content-Disposition: form-data; name="files[]"; filename="Abelson_2834.jpg"
Content-Type: image/jpeg
So "pool" is an array with the keys set as the name and it's value is set aa a string.
from the form that lookes like this basicly
<tbody data-target="#modal-gallery" data-toggle="modal-gallery" class="files">
<tr class="template-upload fade in">
<td class="preview"><span class="fade in">
<canvas width="80" height="54"></canvas>
</span></td>
<td class="name"><span>Abelson_2834.jpg</span></td>
<td class="size"><span>4.17 MB</span></td>
<td><div aria-valuenow="0" aria-valuemax="100" aria-valuemin="0" role="progressbar" class="progress progress-success progress-striped active">
<div style="width:0%;" class="bar"></div>
</div>
<div="forminputs"> <span style="display:inline-block;float:left;">Choose a pool:
<select style="display:inline-block;" name="pool[Abelson_2834.jpg]">
<option selected="selected" value="general_pool">General</option>
<option value="place">Places</option>
<option value="geo">Geometrics</option>
<option value="ads">Advertisment</option>
</select>
<span class="pool_place"> <br>
Choose a pool:
<select style="display:inline-block;" name="pool_place[Abelson_2834.jpg]">
<option selected="selected" value="1">place 1</option>
<option value="2">Places</option>
<option value="3">Geometrics</option>
<option value="4">Advertisment</option>
</select>
</span> </span> <span style="display:inline-block;float:left;">Choose Media type:
<select style="display:inline-block;" name="mediatype[Abelson_2834.jpg]">
<option value="1">marker_icon</option>
<option value="2">user_image</option>
<option selected="selected" value="3">general_image</option>
<option value="4">general_video</option>
<option value="5">google_static_map</option>
</select>
</span> </div="forminputs"></td>
<td class="start"><button class="btn btn-primary"> <i class="icon-upload icon-white"></i> <span>Start</span> </button></td>
<td class="cancel"><button class="btn btn-warning"> <i class="icon-ban-circle icon-white"></i> <span>Cancel</span> </button></td>
</tr>
<tr class="template-upload fade in">
<td class="preview"><span class="fade in">
<canvas width="80" height="54"></canvas>
</span></td>
<td class="name"><span>Abelson_2852.jpg</span></td>
<td class="size"><span>3.17 MB</span></td>
<td><div aria-valuenow="0" aria-valuemax="100" aria-valuemin="0" role="progressbar" class="progress progress-success progress-striped active">
<div style="width:0%;" class="bar"></div>
</div>
<div="forminputs"> <span style="display:inline-block;float:left;">Choose a pool:
<select style="display:inline-block;" name="pool[Abelson_2852.jpg]">
<option selected="selected" value="general_pool">General</option>
<option value="place">Places</option>
<option value="geo">Geometrics</option>
<option value="ads">Advertisment</option>
</select>
<span class="pool_place"> <br>
Choose a pool:
<select style="display:inline-block;" name="pool_place[Abelson_2852.jpg]">
<option selected="selected" value="1">place 1</option>
<option value="2">Places</option>
<option value="3">Geometrics</option>
<option value="4">Advertisment</option>
</select>
</span> </span> <span style="display:inline-block;float:left;">Choose Media type:
<select style="display:inline-block;" name="mediatype[Abelson_2852.jpg]">
<option value="1">marker_icon</option>
<option value="2">user_image</option>
<option selected="selected" value="3">general_image</option>
<option value="4">general_video</option>
<option value="5">google_static_map</option>
</select>
</span> </div="forminputs"></td>
<td class="start"><button class="btn btn-primary"> <i class="icon-upload icon-white"></i> <span>Start</span> </button></td>
<td class="cancel"><button class="btn btn-warning"> <i class="icon-ban-circle icon-white"></i> <span>Cancel</span> </button></td>
</tr>
<tr class="template-upload fade in">
<td class="preview"><span class="fade in">
<canvas width="80" height="54"></canvas>
</span></td>
<td class="name"><span>Abelson_3160-1.jpg</span></td>
<td class="size"><span>3.00 MB</span></td>
<td><div aria-valuenow="0" aria-valuemax="100" aria-valuemin="0" role="progressbar" class="progress progress-success progress-striped active">
<div style="width:0%;" class="bar"></div>
</div>
<div="forminputs"> <span style="display:inline-block;float:left;">Choose a pool:
<select style="display:inline-block;" name="pool[Abelson_3160-1.jpg]">
<option selected="selected" value="general_pool">General</option>
<option value="place">Places</option>
<option value="geo">Geometrics</option>
<option value="ads">Advertisment</option>
</select>
<span class="pool_place"> <br>
Choose a pool:
<select style="display:inline-block;" name="pool_place[Abelson_3160-1.jpg]">
<option selected="selected" value="1">place 1</option>
<option value="2">Places</option>
<option value="3">Geometrics</option>
<option value="4">Advertisment</option>
</select>
</span> </span> <span style="display:inline-block;float:left;">Choose Media type:
<select style="display:inline-block;" name="mediatype[Abelson_3160-1.jpg]">
<option value="1">marker_icon</option>
<option value="2">user_image</option>
<option selected="selected" value="3">general_image</option>
<option value="4">general_video</option>
<option value="5">google_static_map</option>
</select>
</span> </div="forminputs"></td>
<td class="start"><button class="btn btn-primary"> <i class="icon-upload icon-white"></i> <span>Start</span> </button></td>
<td class="cancel"><button class="btn btn-warning"> <i class="icon-ban-circle icon-white"></i> <span>Cancel</span> </button></td>
</tr>
</tbody>
I have tried a few ways to pull out the information but the short of it is that I have to be able to know what the key is so I can test it so I know I'm getting the value. I don't have a choice on the post data, that is stuck the way it is. I can't use things like .ToDictionary cause I'm also stuck in .net 2.0.
Here is an attempt at getting the right info via just KeyValuePair thou yes it's wrong but at least I hope it'll give the idea of what is needing to happen.
media.file_name = "Abelson_2834.jpg"; // test value to pin to
int type = 3;
// NOTE I KNOW KeyValuePair IS NOT RIGHT.. looking for right way thou
foreach (KeyValuePair<string, string> obj in Request.Params["mediatype"])
{
if( obj.Key == media.file_name ){
type = int.Parse(obj.Value);
// value of type should be 3 since there is a
// Request.Params["mediatype"]["Abelson_2834.jpg"] but since you can't call keys
// by name it thnk it should be an int
// like Request.Params["mediatype"][0]
}
}
media.type = ActiveRecordBase<media_types>.Find(type);
ActiveRecordMediator<media_repo>.Save(media);
Anyone have an idea on how to make this work? I would think that turning the String[] to a Dictionary or Hashtable would be the trick but.. as of yet it's not working.
Thank you for the help.
Cheers,
jeremyBass
SIDE NOTE
If this was php, I'd just have to go
$value = $_POST["mediatype"]["Abelson_2834.jpg"];
and I'd have the value needed if that clears things up some.
The input is misleading you. You actually are getting property[object]=value. If you create KVPs with Key = some_function(object,property), Value=value you'll be headed in the right direction. For example, as a one-off of your code above:
if (!String.IsNullOrEmpty(Request.Params["mediatype"])){
foreach (KeyValuePair<string, string> obj in Request.Params["mediatype"])
{
dict_props[obj.Key+"_mediatype"]=value;
// add each object to a list
}
}
// for each object in the list
// for each property
...process dictionary....
The solution is this
media.file_name = "Abelson_2834.jpg";
int type = 3;
int tmp = int.Parse(Request.Params["mediatype[" + media.file_name+ "]"]);
if(tmp>0){
type = tmp;
}
In short you need to target directly at the first level form keys as C# .net 2.0 at least doesn't understand that an array when coming from a post can have a key other then a int. When it sees this what it does is treat it as a string so, you call it as one.
Thanks for the help you guys.
Cheers -Jeremy
I have a list which I created in the controller:
var PayList = new[] {
new ListEntry { Id = 1, Name = "" },
new ListEntry { Id = 2, Name = "Yes" },
new ListEntry { Id = 3, Name = "No" }
};
ViewBag.PayList = new SelectList(PayList, "Id", "Name");
In the view I have the following:
#Html.DropDownList("Pay", new SelectList(ViewBag.PayList,"Id","Name"))
When I try to display it, it says the following:
DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'Id'. Not sure why this is not working.
Also how do I default a value to the select list. I like to default it to "Yes". I thought there was a way to do do this from the controller.
Your ViewBag.PayList is already the type of SelectList. I don't see a reason to create the SelectList twice, so shouldn't it just be:
#Html.DropDownList("Pay", ViewBag.PayList)
or
#Html.DropDownList("Pay", ViewBag.PayList as SelectList)
(I don't ever use the ViewBag, so I'm not sure if your version is strongly typed).
Just use
#Html.DropDownList("Pay", ViewBag.PayList)
In your view
Try this Way:
<div id="divmsg" style="color: green; font-weight: bold">
#ViewBag.Msg
</div>
<div id="divmsg2" style="color: red; font-weight: bold">#ViewBag.Msg2</div>
<div id="quality" style="width: 80%;" align="center">
<input type="hidden" value="#ViewBag.ProjectId" id="ProjectId_" class="projectId"/>
<input type="hidden" value="#ViewBag.ProjectName" id="ProjectName_" class="projectName"/>
<input type="hidden" value="#ViewBag.UserId" class="UserId_" id="UserId"/>
<input type="hidden" value="#ViewBag.TempId" class="TempId_" id="TempId" />
<div class="toggle-contents">
<table width="100%" id="qualitygoal">
<tr>
<td class="even" align="left">
#Html.Label("Project Id")
</td>
<td class="even" align="left">
#ViewBag.ProjectId
</td>
</tr>
<tr>
<td class="projectname" align="left">
#Html.Label("Project Name")
</td>
<td class="projectname" align="left">
#ViewBag.ProjectName
</td>
</tr>
</table>
<table width="100%" id="qualitygoal1" class="tbl">
<tbody>
<tr>
<th align="center">DestinationColumns</th>
<th align="center">SourceColumns</th>
</tr>
#foreach (var data in Model)
{
<tr>
<td>
<span class="spanStatus" id="lblStatus_#data.TempId" destinationID = "#data.Destination">#data.Destinationvalue</span>
<select class="status" id="ddlStatus_#data.TempId">
<option value="0">--Select--</option>
<option value="4">TICKET ID</option>
<option value="5">DESCRIPTION</option>
<option value="6">TICKET CATEGERY</option>
<option value="7">SEVIORITY/PRIORITY</option>
<option value="8">STATUS</option>
<option value="9">CREATED DATE</option>
<option value="10">CREATED BY</option>
<option value="11">ASSIGNED TO</option>
<option value="12">ASSIGNED DATE</option>
<option value="13">REPSONSE ETA</option>
<option value="14">RESOLUTION ETA</option>
<option value="15">RESPONSE DATE</option>
<option value="16">RESOLUTION DATE</option>
<option value="17">ROOT CAUSE/MODULE</option>
<option value="18">REOPEN FLAG (Y/N)</option>
<option value="19">CLOSE DATE</option>
<option value="20">SLA MET (Y/N)</option>
</select>
</td>
<td>
<span class="spanSource" id="lblSource_#data.TempId" >#data.Source</span>
<input class="Source" id="txtSource_#data.TempId" type="text" value="#data.Source" maxlength="30" />
</td>
<td>
<table style="width: 50%;">
<tr>
<td>
<input class="edit" id="Edit_#data.TempId" type="button" value="Edit" />
<input class="update" id="Update_#data.TempId" type="button" value="Update" />
</td>
<td class="Gcancle" id="Canc_#data.TempId">
<input class="gridcancel" id="Cancel_#data.TempId" type="button" value="Cancel" />
</td>
</tr>
</table>
</td>
<td>
<table style="width: 50%;">
<tr>
<td>
<input class="delete" id="Delete_#data.TempId" type="button" value="Delete" />
</td>
</tr>
</table>
</td>
</tr>
}
</tbody>
</table>
</div>
<div align="right">
<input type="button" value="Add New Row" class="Add" />
<input type="button" value="Save" class="saved" />
<input type="button" value="Close" class="cancel" />
</div>
</div>