从Web浏览器中选择一个下拉选项 [英] Selecting a dropdown option from webbrowser

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

问题描述

我的目标是选择第二个选项.

My goal I need to select the second option.

我尝试了以下方法,但无法设置所选值.没有错误显示,选择只是没有发生.我自己对HTML非常熟悉,我知道"selected"和"selected ="selected"可以工作,但不确定为什么它不能与我的C#代码一起工作.有什么问题吗?

I've tried following approach and can't set selected value. No error shows up, the selection just doesn't happen. Being very familiar with HTML myself, I know that "selected" and 'selected="selected"' work but not sure why it's not working with my C# code. What could be wrong?

webBrowser1.Document.GetElementById("field_gender1").
       Children[1].SetAttribute("selected", "selected");

HTML是

<select name="gender1" id="field_gender1" class="select">
        <option selected="selected" value="1">val1</option>
        <option value="2">val2</option>
</select>

推荐答案

如果您的代码在适当的位置,则应该可以正常工作,例如:button1_Click事件,webBrowser1_DocumentCompleted事件等.

Your code should be working if it's at a suitable place, eg: button1_Click event, webBrowser1_DocumentCompleted event, etc.

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

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