WebBrowser控件HTMLDocument的自动选择选项下拉 [英] WebBrowser control HTMLDocument automate selecting option drop-down

查看:621
本文介绍了WebBrowser控件HTMLDocument的自动选择选项下拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用WebBrowser控件导航和拉报告从一个网站上的信息一个WinForm实现自动化。您可以在文本框输入值并调用的按钮和链接点击事件,但我还没有想出如何选择一个选项下拉....以自动化的方式。有人建议如何选择从下拉列表中的项目,因为这个网站的例子:

I'm trying to automate in a WinForm using a WebBrowser control to navigate and pull report info from a website. You can enter values in textboxes and invoke the click events for buttons and links, but I have not figured out how select a option drop-down .... in a automated way. Anybody recommend how to select a item from a drop-down, given this html example:

<SELECT id="term_id" size="1" name="p_term_in"><option value="">Select Another Term<option value="201050">Summer 2010<option value="201010">Spring 2010<option value="200980">Fall 2009</SELECT>

对于其他人,可以从这里进入值文本框和调用点击事件中吸取是你如何做到这一点:

For others that can learn from entering values to textboxes and invoking click events here's how you do it:

webBrowser1.Document.GetElementById("<HTML ELEMENT NAME>").SetAttribute("value", "THE NAME");

调用按钮或超链接点击:

Invoke button or hyperlink click:

webBrowser1.Document.GetElementById("<BUTTON>").InvokeMember("click");

所以,我已经解决了输入值和调用一下,但我还没有解决选择下拉值。

So I've solved entering values and invoking click, but I have not solved selecting a drop-down value.

推荐答案

假设你在HTML以下选择:

Assuming you have the following select in the HTML:

<select id="term_id" size="1" name="p_term_in">
    <option value="">Select Another Term
    <option value="201050">Summer 2010
    <option value="201010">Spring 2010
    <option value="200980">Fall 2009
</select>

这应该允许您preSELECT第三个值:

This should allow you to preselect the third value:

webBrowser1.Document.GetElementById("term_id").SetAttribute("value", "201010");

这篇关于WebBrowser控件HTMLDocument的自动选择选项下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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