【发布时间】:2015-10-04 12:34:26
【问题描述】:
我正在使用 C#,win 应用程序,试图单击在我的网络浏览器的 iframe 中找到的按钮。
HTML:
<iframe frameborder="0" scrolling="no" id="EditorIFrmae" name="EditorIFrmae" width="100%" height="700" style="z-index: 0; height: 852px;" src="X"></iframe>
在 iframe 代码中:
<div height="" width="100%" style="position: relative; min-height: 50px;" onclick="javascript:funcEditPage('SB_Content_Page','SB_Content_PagePreview','PAGE5.asp');" class="SB_DivContentPreview" id="SB_Content_PagePreview">
</div>
我的代码:
HtmlElementCollection linkit = this.webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement foundit in linkit)
{
if (foundit.GetAttribute("id").Equals("SB_Content_PagePreview"))
{
foundit.InvokeMember("Click");
}
}
我怎样才能点击按钮?
【问题讨论】:
-
非常不清楚的问题。具体是什么问题
-
@FarhanAnam - 对不起,这还不够清楚:我试图点击在 ifame 而不是当前页面上找到的 div。
-
您的代码看起来不错您遇到了什么问题?
-
@FarhanAnam - 我猜问题是我的代码找不到 div,因为他在 iframe 页面中而不是在当前页面上。我得到的错误是 - div not found
-
哦,所以按钮没有被点击。你在问题中没有提到这个事实。无论如何,回到问题,如果您不需要显示页面,则应该使用 HTML Agility Pack 而不是 WebBrowser。
标签: c# winforms iframe webbrowser-control