2

In the following picture I am trying to click the option 50 from this drop down menu which is implemented in a table in html structure Any help please enter image description here

I tried this line

.document.getElementByName("WatchedCompaniesGrid_length").Value = "50" 

But this throws an error

I also tried those lines

 Set oElt = ie.document.getElementsByName("WatchedCompaniesGrid_length") If Not oElt Is Nothing Then oElt(0).Value = "50" End If 

and it actually selects the option but doesn't trigger the event .. I tried oElt.FireEvent "onchange" but doesn't work for me

This is html lines

<input name="WatchedCompaniesGridSelectedId" id="WatchedCompaniesGridSelectedId" type="hidden" value="" autocomplete="off"><script language="javascript" type="text/javascript">WatchedCompaniesGridinit = new RegSysPortal.Grid();WatchedCompaniesGridinit.Initialise('WatchedCompaniesGrid','','','','','','', '', '', 'false', 'true', 'true', 'true', 'two_button', '5', 'asc', '', '10', '1,R,3,C,4,C,5,C,6,C,7,C,8,C', '0', '0', '', '0', null, false, false);</script><div class="frmResponse_blank" id="WatchedCompaniesGrid_result"><span class="frmResponse_message_span"></span></div> <div class="dataTables_wrapper" id="WatchedCompaniesGrid_wrapper" role="grid"><div class="fg-headerbar"><div class="dataTables_length" id="WatchedCompaniesGrid_length"><span><table><tbody><tr><td>Show </td><td><select name="WatchedCompaniesGrid_length" aria-controls="WatchedCompaniesGrid" size="1"><option value="5">5</option><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select></td><td>entries</td></tr></tbody></table></span></div><div class="dataTables_filter" id="WatchedCompaniesGrid_filter"><span><table><tbody><tr><td>Search:</td><td><input aria-controls="WatchedCompaniesGrid" type="text" autocomplete="off"></td></tr></tbody></table></span></div></div><table class="z-index: 2000 dataTable" id="WatchedCompaniesGrid" aria-describedby="WatchedCompaniesGrid_info" style="width: 987px;">

** this is html part

<table><tbody><tr><td>Show </td><td><select name="WatchedCompaniesGrid_length" aria-controls="WatchedCompaniesGrid" size="1"><option value="5">5</option><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select></td><td>entries</td></tr></tbody></table>

0

2 Answers 2

3

First thing first what version of IE are you using? Cause it will depend on what is the event trigger for this selection.

You can try this to select the index of that selection based on the option value.

Set oElt = ie.document.getElementsByName("WatchedCompaniesGrid_length") For a = 0 To oElt.Options.Length - 1 If oElt.Options(a).Text = "sample Option Value" Then oElt.selectedIndex = a Exit For End If Next 

Now for the event trigger part. After you select your desired option.

In IE11 you can try this one.

Dim objEvent Set objEvent = IE.Document.createEvent("HTMLEvents") 'Create an event handler for IE.Document objEvent.initEvent "change", False, True oElt.dispatchEvent objEvent 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very very much. That helped me a lot
2

Try this. I used hardcoded delay to let the browser update it's content. The selector is able to select and change the desired number from dropdown. However, the only porblem was that the new content never updated unless we opted for keyboardevent.

Dim Html As HTMLDocument, post As Object, , evt As Object Set Html = IE.document ''without this line queryselector fails sometimes Application.Wait Now + TimeValue("00:00:03") Set post = Html.querySelector("select[name='WatchedCompaniesGrid_length']") post.selectedIndex = 3 

This is the portion that made that webpage update the result. I tried to show how you can use it in your script.

Set evt = Html.createEvent("keyboardevent") evt.initEvent "change", True, False Set post = Html.querySelector("select[name='WatchedCompaniesGrid_length']") post.selectedIndex = 3 post.dispatchEvent evt 

8 Comments

Thanks a lot for reply. I encountered a run-time error '438' (Object doesn't support this property or method)
Can you update your post with the portion of html you have pasted as image above so that I can test it locally? That image cant be reused. Thanks.
Check out the edit. it should work now. I used .queySelector() instead of .querySelector(). Missed the r let alone a silly mistake was there.
There's no error now but the loop is infinite ..What should I do?
Kick out the loop and put a hardcoded delay to see what happens. Are you sure that very portion is not within iframe?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.