从IE中的下拉菜单中选择一个项目 [英] Select an item from drop down in IE

查看:75
本文介绍了从IE中的下拉菜单中选择一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的图片中,我尝试从此下拉菜单中单击选项50,该选项在html结构表中实现 有什么帮助吗

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

我尝试了这一行

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

但这会引发错误

我也尝试过这些线

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

End If

它实际上选择了选项,但没有触发事件..我尝试了oElt.FireEvent"onchange",但对我不起作用

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

这是html行

<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;">

**这是html部分

** 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>

推荐答案

尝试一下.我使用硬编码延迟来让浏览器更新其内容.选择器可以从下拉列表中选择和更改所需的数字.但是,唯一的问题是,除非我们选择keyboardevent,否则新内容永远不会更新.

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

这篇关于从IE中的下拉菜单中选择一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆