Im working a web browser automation project.
this is exampel code ;
<select name="ctl00$ctl00$main$Content$cbReceiverCity" id="ctl00_ctl00_main_Content_cbReceiverCity" tabindex="40" class="custom-select" onchange="javascript:GetTowns(this);void(0);" style="width:170px;" size="5">
<option selected="selected" value="-1">-- choose one --</option>
<option value="1">Portugal</option>
<option value="2">Spain</option>
<option value="3">France</option>
<option value="4">Germany</option>
<option value="5">Italy</option>
</select>
and my c# code;
HtmlElement enter =
webBrowser1.Document.GetElementById("ctl00_ctl00_main_Content_cbReceiverCity");
enter.SetAttribute("selectedIndex", "5");
enter.InvokeMember("onchange");
but,Index value does not change. How can I change this?
Replace this
enter.SetAttribute("selectedIndex", "5");
with this
enter.Children[5].SetAttribute("selected", "selected");
where 5 is the index of the option you want to select
Related
I have an ASP.NET Core 2.0 web application that generates a multi-select list box using bootstrap-multiselect (basically a prettied up list box control)
The code generated is shown:
<select class="multiselect-ui form-control" id="Issues" multiple="multiple" name="Issues">
<option selected="selected" value="1">Dilapidated Structures</option>
<option selected="selected" value="3">Junk on Premises</option>
<option selected="selected" value="4">Junk Vehicles</option>
<option selected="selected" value="5">Minor Maintenance</option>
<option selected="selected" value="6">Miscellaneous</option>
<option selected="selected" value="7">Overgrowth</option>
<option selected="selected" value="8">Right of Way</option>
<option selected="selected" value="9">Sidewalks</option>
<option selected="selected" value="10">Trash</option>
<option selected="selected" value="2">Weeds/High Grass</option>
</select>
When this is submitted in a form, I see the Issues being added to the URL like so:
/Cases?Issues=1&Issues=3&Issues=4&Issues=5 ...
This is great and I am able to retrieve the values in my controller using a List<string> object. My question is, how would I add a hyperlink to the page that uses the values already sent via GET? Basically I would like to use Tag Helpers, but there is no way to add an array of values that I've found. There are dictionary key/pairs, but of course you are not able to add multiple values with the same key. I would like to be able to reference a List<string> in the tag helper itself (the following does not work, but should give an idea of what I'm after if I am sending the List<string> back using ViewBag):
<a asp-route-Issues=#ViewBag.IssuesList>Next</a>
I found out through this link that this feature isn't implemented. I used #Url.Action to build my link as shown (where ViewBag.IssuesList contains the List<string> -- I also left out some paramters for brevity:
Previous
I need help. How can i select a dropdown item that does not have the selected attribute in C# using Webkit? The html is :
<select id="question" name="questionId">
<option value="">Text</option>
<option value="1">
Question 1
</option>
<option value="2">
Question 2
</option>
</select>
I have code Html as following:
<select name="film_episode">
<option value="1111">Post 1</option>
<option value="2222">Post 2</option>
<option value="3333">Post 3</option>
</select>
how to use 'webbrowser' in c# click on selected automatically 'Post 2'.
Please help me. Thank you very much.
Use this to get things easier
<select runat="server" id="dropDownList1" name="film_episode">
<option value="1111">Post 1</option>
<option value="2222">Post 2</option>
<option value="3333">Post 3</option>
</select>
in Code behind(aspx.cs)
dropDownList1.Items.FindByText("Post 2").Selected = true;
I would like to modify the selected value of my dropdownlist without have to click on my dropdownlist.
I already tried this line with JQuery:
$('#select-nb-Persons-button').children(":first").text("3");
It printed well "3" for the dropdownlist but after, when I clicked on the dropdownlist, I noticed that it is always the first option tag that is selected and not the third option tag as I want. :
Code created by razor for the dropdownlist :
<div class="ui-select">
<div id="select-nb-Persons-button" class="ui-btn ui-icon-carat-d ui-btn-icon-right ui-corner-all ui-shadow">
<span>1</span>
<select data-val="true" data-val-number="Le champ nbPersons doit être un nombre." data-val-required="Le champ nbPersons est requis." id="select-nb-Persons" name="nbPersons">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
</div>
Can you help me please ?
Thank you
You can use val() to set the selected item in a select. To select the item with a value of 3, try this:
$('#select-nb-Persons').val('3');
Try below code.
$('#select-nb-Persons-button').children('select').val('5');
DEMO here
I am using this code on my Master page and wants to display option name on the reffered page
<select name=menu onchange="location.href=(menu.options[menu.selectedIndex].value)">
<option value="http:google.com">Google</option>
<option value="http:myurl.com">URL</option>
</select>
You need to use this to refer to event source object instead of menu the name of html element. You also have wrong url form and need to change it from http:google.com to http://google.com
Live Demo
<select name=menu onchange="window.location.href=(this.options[this.selectedIndex].value)">
<option value="http://www.google.com">Google</option>
<option value="http://www.stackoverflow.com">stackoverflow</option>
</select>