How to Get element of Iframe?
i want to automate page using web browser automation.
In the there is only an iframe at runtime value comes to that iframe.
when i try get the value of i frame it returns only the iframe not whole page html,
I want to click a href of i frame.
Please help me to solve this problem I am code.
HtmlDocument dd = (HtmlDocument)loginBrowser.Document.GetElementById("UIFrame"开发者_高级运维);
Try
HtmlDocument.contentWindow.body
I have no idea of c# and what you are doing (I'm a PHP man mainly these days) but it looks to me like you are casting an IFrame element to a HTMLDocument type? This may be wrong, as the IFrame element is not identical with the body
. Is that casting really necessary? Maybe cast it to a HTMLElement instead?
You probably want
HtmlDocument.Body
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument_members.aspx
the Body is an
HtmlElement
, which has properties for the InnerHtml
and InnerText
, if you want to look for data returned in the IFrame document.
See the following for more on HtmlElement http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.aspx
Also, are you sure you want to be casting to HtmlDocument
? Looking at MSDN, it looks like GetElementById() should return an HtmlElement.
If jQuery is available in your target website then try this:
browser.Document.InvokeScript("eval", new object[] { "$(\"#iframe_id\").contents().find('#element').html())" });
精彩评论