我正在尝试使用axwebBrowser控件在网页中选择一个选项。

我知道如何选择一个值,这是我的代码:
mshtml.IHTMLElement ddlid1b = doc.getElementById(“ id56”);
ddlid1b.children [3] .SetAttribute(“ selected”,“ selected”);

之后,我触发了如下所示的Change Event

var el3 =(ddlid1b为IHTMLElement3);
el3.​​FireEvent(“ onchange”);

但是有一个问题,当更改值时网站自动刷新,因此当我使用我的代码时,选择框中的值更改,但是网站不刷新。

是否可以像.aspx pages中一样发回页面。

我该如何工作?

先感谢您

最佳答案

最后,我使用时间控制解决了这个问题。

完成下拉选择事件后,我们需要启动计时器

mshtml.IHTMLElement ddlid1b = doc.getElementById(“ id56”); ddlid1b.children [3] .SetAttribute(“ selected”,“ selected”);
var el3 =(ddlid1b为IHTMLElement3);
el3.​​FireEvent(“ onchange”);

Timer.Start();

在Tick事件中,我们需要下载并执行操作

  private void timer1_Tick(object sender, EventArgs e)
    {
       try
        {

                timer1.Stop();
                mshtml.HTMLDocument doc1 = (mshtml.HTMLDocument)axWebBrowserClaims.Document;
                IHTMLElementCollection col = doc1.forms;

                mshtml.HTMLDocument doc3 = (mshtml.HTMLDocument)axWebBrowserClaims.Document;
                string html2 = doc3.body.innerHTML;

                mshtml.IHTMLElement ddlStates = doc3.getElementById("ddlStates");
                ddlStates.children[1].SetAttribute("selected", "selected");


                mshtml.IHTMLElement txtDistrict = doc3.getElementById("txtDistrict");
                txtDistrict.innerText = "Khammam";

                mshtml.IHTMLElement btnSubmit = doc3.getElementById("btnSubmit");
                btnSubmit.click();
            }

        }
        catch (Exception ex)
        {
        }
    }


谢谢...

关于c# - 在axwebBrowser控件中未刷新选择选项页后的C#,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28535475/

10-11 22:48
查看更多