1

I am trying to select a value from a dropdown in a web page using Seleinum with VBA binding, but I am unable to do it.

This is the code I tried bot.FindElementById("holder-samples-date-type-inputEl").SendKeys "XX"

I am not getting any error the code runs it click the dropdown button and the list is shown but no value is selected and the dropdown does not change.

I have the same project with VBA and IE (DOM elements) and this code works fine in Internet explorer IE.document.getElementById("holder-samples-date-type-inputEl").Value = "XX"

The interesting part of this dropdown is after clicking the dropdown icon i am unable to inspect the list (like do a right click on the list) and if i click anywhere else in the web page or change the window the dropdown list get closed (like it retracts) note: this is not a mouseover drop down. Also, when the list is open there seems to be additional code added (I have pasted a snippet of the code)

Below is the HTML from the web page.

<div id="holder-samples-date-type-triggerWrap" data-ref="triggerWrap" class="x-form-trigger-wrap x-form-trigger-wrap-default x-form-trigger-wrap-invalid"> <div id="holder-samples-date-type-inputWrap" data-ref="inputWrap" class="x-form-text-wrap x-form-text-wrap-default x-form-text-wrap-invalid"><input id="holder-samples-date-type-inputEl" data-ref="inputEl" type="text" role="combobox" aria-label="Chargebacks: Date Type" aria-readonly="false" aria-required="true" aria-haspopup="true" aria-expanded="false" aria-autocomplete="list" size="1" name="P_samples_Date_Type" readonly="readonly" class="x-form-field x-form-required-field x-form-text x-form-text-default x-form-invalid-field x-form-invalid-field-default" autocomplete="off" aria-labelledby="holder-samples-date-type-labelEl" aria-owns="boundlist-1206" componentid="holder-samples-date-type" data-errorqtip="<ul class=&quot;x-list-plain&quot;><div>Date Type</div><li>This field is required</li></ul>" aria-invalid="true"></div> <div id="holder-samples-date-type-trigger-picker" aria-label="Trigger" class="x-form-trigger x-form-trigger-default x-form-arrow-trigger x-form-arrow-trigger-default "><img class="combo-trigger-placeholder" src="https://www.sample.net/clr/images/16x16_transparent.png" title="combobox trigger" alt="combobox trigger"></div> </div> 

Below is the image enter image description here

Since I am unable to do a right click on the dropdown option. I did a 'Find" option in the developer window and below is the webpage code for the dropdown item and it is inside a iframe

<div id="boundlist-1206-listWrap" data-ref="listWrap" role="presentation" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;"> <ul id="boundlist-1206-listEl" data-ref="listEl" class="x-list-plain"> <div data-qtip="" class="x-boundlist-item x-boundlist-item-over" tabindex="-1" data-recordindex="0" data-recordid="31" data-boundview="boundlist-1206" id="ext-932" role="option" aria-selected="false">Received Date</div> <div data-qtip="" class="x-boundlist-item" tabindex="-1" data-recordindex="1" data-recordid="32" data-boundview="boundlist-1206" id="ext-933" role="option" aria-selected="false">Status Date</div> <div data-qtip="" class="x-boundlist-item" tabindex="-1" data-recordindex="2" data-recordid="33" data-boundview="boundlist-1206" id="ext-934" role="option" aria-selected="false">Due Date</div> <div data-qtip="" class="x-boundlist-item" tabindex="-1" data-recordindex="3" data-recordid="34" data-boundview="boundlist-1206" id="ext-935" role="option" aria-selected="false">Disposition Date</div> </ul> </div> 
3
  • where is the html for the options list ? Are you unable to copy as you mention above?
    – QHarr
    CommentedFeb 6, 2019 at 17:48
  • Just now I had that strike, so I did a 'Find" option in the developer window and pasted the code to my question. This is not a public site so I am sorry it cannot be shared.
    – David
    CommentedFeb 6, 2019 at 17:57
  • You will need to switch to the iframe first
    – QHarr
    CommentedFeb 6, 2019 at 18:00

1 Answer 1

1

Some points that may help:

1) If inside an iframe you will need to switch to the iframe first

bot.SwitchToFrame(identifier) 

Identifier can be the element selected by iframe name/id etc.

2) You can try click and hold on the input text box before using your SendKeys

bot.FindElementById("x").ClickAndHold 'sendkeys line here 

3) You can try setting the value with javascript

bot.ExecuteScript "document.getElementById('x').value = 'xx';" 
5
  • This code works like magic bot.ExecuteScript "document.getElementById('x').value = 'xx';" But do you know where I can learn more about this as I do not know Javascript. and it is a surprise to me that Javascript can be used in VBA.
    – David
    CommentedFeb 6, 2019 at 18:37
  • It is not considered best practice from testing a websites functionality point of view in automation but I am usually more concerned about getting the job done in a consistent manner.
    – QHarr
    CommentedFeb 6, 2019 at 18:40
  • Not at all. Purists will want everything done by automating button pushing etc... I have cheated by running javascript to achieve the end goal. If you were testing the website functionality you would, however, want to be sure you could make selections from the dropdown via automation of click etc.....
    – QHarr
    CommentedFeb 6, 2019 at 18:46
  • Glad to hear it, Do you have any links to learn about this or is it entirely different subject where I have learn java first?
    – David
    CommentedFeb 6, 2019 at 18:49
  • It is javascript not java. And knowing enough javascript to write statements like the above I think is a real bonus for web-scraping. I think it is also helpful for debugging pages, understanding what a webpage is doing. The line above is basically the same as you do in vba so no real learning curve there apart from knowing how to phrase it in the javascript way and wrap it in .execute statement. Doing a couple of beginner javascript lessons and knowing your vba scraping well should be enough for the simple cases.
    – QHarr
    CommentedFeb 6, 2019 at 18:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.