VBA IE11 locking in a change to a dropdown value - vba

I'm using VBA to open a website, login, and navigate to a certain page. There is a dropdown with 8 options.
I used this code to change the dropdown to the value I want, but it always reverts back to the default as I continue. How do I lock this change in?
Set Element = IE.Document.getElementsByName("date_range")
Element.Item(0).Value = "custom"
Here's the page code:
<div class="SelectInput">
<select class="SelectInput-select" name="date_range">
<option value="all_time">All Time</option>
<option value="today">Today</option>
<option value="yesterday">Yesterday</option>
<option value="this_month">Month to date</option>
<option value="last_month">Last Month</option>
<option value="this_year">Year to date</option>
<option value="last_year">Last year</option>
<option value="custom">Between...</option>
</select>
<div class="SelectInput-arrows">...</div>
</div>
Thanks,

you need to set the selected attribute .... ref: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_option_selected

Related

Excel VBA drop down box queryselection code doesn’t work to submit for update

This line of code in my excel macro
IE.document.querySelector("option[value='4000']") doesn't work.
What selection query code works for this site? https://www.corsicahockey.com/nhl/players/nhl-player-ratings-rankings.
The HTML website code is:
<div class="col">
<div class="d-flex flex-nowrap justify-content-lg-end">
<label class="d-none d-sm-inline-block">Show</label>
<select id="filter_limits_select">
<option value='10' >10</option>
<option value='25'>25</option>
<option value='50'>50</option>
<option value='100'selected>100</option>
<option value='200'>200</option>
<option value='500'>500</option>
<option value='4000' >All</option>
</select>
I can properly select the change option value = "4000". But the ie.document.selection query code does not submit for update. Do you have the correct code that will work for this website?

VBA: Value change on a dropdown in IE doesn't update report

I'm automating the download of a report. There is a dropdown for status that needs changing to the value "Started". I've managed to change the value in my code but when you manually make the change the report screen for the site updates automatically. My code doesn't manage to do this.
I'm wondering if there's an extra element that might need changing. Does anyone have any idea what I'm missing?
element on the site:
<select data-bind="value: leads.overall_status, options: [null, 'not_started', 'quoted_with_quotes', 'quoted_without_quotes', 'started', 'open_accounts'], optionsText: BrokerLeadsGridModel.overall_status_renderer" style="width: 160px;vertical-align: baseline;display: inline;" class="form-control">
<option value="">Any</option>
<option value="not_started">Not Started</option>
<option value="quoted_with_quotes">Quoted</option>
<option value="quoted_without_quotes">No Quotes</option>
<option value="started">Started</option>
<option value="open_accounts">Open</option>
</select>
My Code:
Doc.getElementsByClassName("form-control")(0).Value = "started"
Did you try attribute = value css selector?
doc.querySelector("[value=started]").selected = True

Angular 5 dropdown setting default value

I am trying to preselect (set as default) value from Angular 5 drop down.
There are three values and I am trying to set the second one with this code but it doesn't work. I can't make any changes in the component, only in the template.
<select [(ngModel)]="declaration.media" name="media" (change)="onChangeMedia()" class="form-control form-control-sm" required>
<option *ngFor="let media of mediaArray" value="{{media.value}}" selected = "{{media.value == '02'}}">{{media.text}}</option>
</select>
UPDATE: if I remove [(ngModel)] then it works, but no two way binding.
<select>
<option value="" selected disabled hidden>Choose here</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>

IE11 drop down item highlighted but should not be

I'm working on a project that has an IE11 specific problem and thought you may be able to help.
When I am in Chrome and have selected an item in a drop-down, the selected item is not highlighted:
But in IE11, I get the following:
Keep in mind that if I click anywhere on the page, the highlight goes away. However the powers that be on my project don't want the highlight to show up at all.
Here's my code for this selection area:
<select name="ms-select-pricebook" id="ms_select_pricebook" title="Pricebook" alt="Pricebook">
<option value="1">Pricebook 1</option>
<option value="2">Pricebook 2</option>
<option value="3">Pricebook 3</option>
<option value="4">Pricebook 4</option>
<option value="5">Pricebook 5</option>
</select>
Any feedback is appreciated!
Thanks,
Chris

How to get displayed text from disable dropdown list?

how can i get visible value from disable dropdown list ?
Best Regards,
thank you
You can use selenium.getSelectedValue() or selenium.getSelectedLabel(). Both are described here.
If you have a dropdown list defined as follows:
<select name="dropdown" disabled>
<option value="1">one</option>
<option value="2">two</option>
<option selected value="3">three</option>
<option value="4">four</option>
</select>
Then you can use the following script to assert that the (disabled) selected label is 'three'.
String selectedLabel = selenium.getSelectedValue("name=dropdown");
assertEquals("three", selectedLabel);