Webbrowser select value from dynamic combobox - html

I am trying to automate a form being filled out with the webbrowser control for VB.NET
The problem is that there is two comboboxes, the second having its values generated depending on the first one.
I can get the correct index to be selected for the first combobox, but for the second the values are never generated. I have to manually select another value for the first combobox and then the second is populated.
I have tried setting/removing focus of the first combobox to try and get the second to populate, but that has not worked.
My current code is:
''Select from the first combo box
Dim make As HtmlElement
make = WebBrowser1.Document.GetElementById("cars.carmake_s")
make.SetAttribute("selectedIndex", 1)
WebBrowser1.Update()
''Should select the second value, but doesn't
Dim model As HtmlElement
model = WebBrowser1.Document.GetElementById("cars.carmake_s+cars.carmodel_s")
model.SetAttribute("selectedIndex", 2)
WebBrowser1.Update()
The HTML code that I am playing with is (cut down):
<div class="form-row clearfix">
<label for="cars.carmake_s">
Make<span class="orange">*</span>
</label>
<div class="form-value">
<div class="c-select-list c-slctbx-medium">
<span class="c-icon c-icon-arrow-green-down"></span>
<select id="cars.carmake_s" name="attributeMap[cars.carmake_s]" class="c-slctbx-depnode c-slctbx-medium" name="attributeMap[cars.carmake_s]"><option value="">Please choose</option>
<option value="alpharomeo"
>
Alfa Romeo</option>
....
...
...
</select></div>
</div>
<div class="form-row clearfix">
<label for="cars.carmodel_s">
Model<span class="orange">*</span>
</label>
<div class="form-value">
<div class="c-select-list c-slctbx-medium">
<span class="c-icon c-icon-arrow-green-down"></span>
<!-->####This is the second combobox and gets populated depending on the first combobox<!-->
<select id="cars.carmake_s+cars.carmodel_s" name="attributeMap[cars.carmodel_s]" class=" c-slctbx-medium" name="attributeMap[cars.carmodel_s]"><option value="">Please choose</option>
</select></div>
</div>
</div>

You might try the following:
curElement.SetAttribute("Value", "Value You Want")
curElement.RaiseEvent("onchange")

Related

.NET Core MVC - DropDownList from Enumerable produces an "multiple" - How to remove?

I have a Site with a Row "Employees", which has eight Dropdowns. To these Dropdowns I have bound a ViewBag with all the Employees and the same List Property.
THe problem with this is that it will produce an "multiple" HTML output, where I can select multiple Employees and the whole Dropdown is showing as a List.
Basically:
<div class="row">
<div class="col-sm">
<select asp-for="Employees" asp-items="ViewBag.Employees" class="form-control" > </select>
</div>
<div class="col-sm">
<select asp-for="Employees" asp-items="ViewBag.Employees" class="form-control"> </select>
.......
In the Model:
public ICollection<int?>? Employees { get; set; }
When I run this Page: 1.) The Dropdown will be "multiple select" and 2.) The Dropdown is shown like a List. It shows all the Employees openly without clicking on it.
Can I somehow prevent this without declaring eight "Employee 1-8" Properties?
Because your type is ICollection<int?>?, So asp-for will generate multiple="multiple" property, You just need to use name="Employees" instead of asp-for="Employees" in this case.
Code:
<div class="col-sm">
<select asp-for="Employees" asp-items="ViewBag.Employees" class="form-control"> </select>
</div>
<div class="col-sm">
<select name="Employees" asp-items="ViewBag.Employees" class="form-control"> </select>
</div>
View:

Using <p-dropdown> with form control

I think I am having an issue with value binding. I have 2 dropdowns on my page currently. The rest of the page is using PrimeNg for UI and would like to make these dropdowns look the same as the rest of the page. How should I go about making this work.
One dropdown is a supervisor list.
<div class="ui-g form-group">
<label for="supervisors">Supervisors * </label>
<select
class="form-control"
id="supervisors"
required
[(ngModel)]="model.supervisor"
name="supervisor"
>
<option *ngFor="let sup of supervisors" [value]="sup">
{{sup}}
</option>
<div
[hidden]="supervisors.valid || supervisors.pristine"
class="alert alert-danger"
>
Supervisor is required
</div>
</select>
</div>
The other is a leave code list
<div class="ui-g-12 ui-md-1" id="test">
<label for="codes">Leave Codes * </label>
<select
class="form-control"
id="codes"
placeholder="Select Leave Code *"
required
[(ngModel)]="model.code"
name="code"
>
<option *ngFor="let cod of codes" [value]="cod">{{cod}}</option>
</select>
</div>
I have 2 arrays of values being called from my .ts file
supervisors = ['Alex',"Jones",'Joe','Rogan'];
codes = ['Personal Leave','Vacation Leave', 'Sick Leave'];
When I use the tags I just get an empty drop down. I tried just using initially but then I was not able to get the required fields to validate.
Did you import DropdownModule?
import {DropdownModule} from 'primeng/dropdown';
See the documentation, html binding should be
<p-dropdown [options]="supervisorList" [(ngModel)]="supervisor"></p-dropdown>
where supervisorList will be defined as SelectItem in controller and needs to be in a label + value format.
supervisorList: SelectItem[];
this.supervisorList= [
{label: 'Alex', value: 'Alex'},
...
];

How to get validate select depending on another select

I have a doctor list. And each doctor has his procedures. How can I apply selected doctor's procedures to procedures selection.
html
<div class="form-group">
<label for="doctors">Doctor</label>
<select [formControl]="selectControl" class="form-control" id="doctors">
<option value="doctor"*ngFor="let doctor of doctors">{{doctor.username}}</option>
</select>
</div>
<div class="form-group">
<label for="procedures">Select Procedure</label>
<select *ngIf="selectControl.valid" class="form-control" id="procedures">
<option *ngFor="let p of selectControl.value.procedures">{{p}</option>
</select>
</div>
.ts
selectControl: FormControl = new FormControl();
For select control, the option value has to be binded to [ngValue] instead of value property.
Here is a working sample showing how to bind to doctors array and then how to retrieve the value of the selectedProcedure.
PS - Instead of creating a formControl, I personally find it more convenient to use formBuilder instead

Angular: How to programatically set select/select2 value after onSubmit()

I'm using HTML <select> Tag, so as it is known allready:
The element is used to create a drop-down list.
The tags inside the element define the available
options in the list.
I want to achieve next thing:
after I select value in a drop-down list I would like to set select's value to a default value which is "-/-" ..
Here is how it looks:
And code:
<div class="form-group">
<label class="control-label dash-control-label col-sm-3" for="">Select Select2:</label>
<div class="col-sm-3">
<select id="taxSelect" class="form-control dash-form-control select2" style="width: 100%;" data-minimum-results-for-search="Infinity">
<option disabled [ngValue]="null" >-/-</option>
<option *ngFor="let code of codes" [value]="code.id">
{{code.title}}
</option>
</select>
</div>
I mean when I open modal again I want to see "-/-" as it is default value, and not the value that I previously selected.. So basically onSubmit() in typescript I would like to reset to set again "-/-" as a default value..
P.S I've tried:
show() {
$('select').val('0');
$('select').val($('select').children().eq(0).val());
$('select2').val('0');
$('select2').val($('select').children().eq(0).val());
$("select[title='-/-']").attr('selected', 'selected');
}
So basically when Modal is shown I wanted to reset drop-down values to "-/-" but it doesn't work..
Thanks a lot guys!
CHEERS!

enable checkbox with id only

I want to fill a HTML form, I am using mechanize module of python.
my HTML code is like that for checkbox and dropdown is :
<div id="post_cd">
<input role="checkbox" id="cd_info" class="cbox" type="checkbox">
<span class="s-iso" style="display:none"></div>
<label for="type" id="cdtype" class="cd" style="width:60px;margin:1px;float:left;text-align:right;">CD type:</label>
<select id='cdtype' class=" ui-iso" style="width:100px;margin:1px;float:left;">
<option value="CD1">Error1</option>
<option value="CD2">Error1</option>
<option value="CD3">Error2</option>
</select>
I have tried with following but getting errors:
for checkbox: form.find_control("cd_info").items[0].selected = True
for dropdown: form['cdtype']= ['Error1']
error:
raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'cd_info'
raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'cdtype'
There is no <form> in your HTML code. So probably form is not pointing to an element around the HTML code you provide at the moment you call find_control or the subscription operator.
You can try to print the text of the form to be sure you are looking at the right thing:
print form