I'm having problems picking out data I need that's inside an iframe form. Is it even possible using HtmlAgilityPack? Here's a screenshot using Firebug so it's easier for you guys to see.
http://i.stack.imgur.com/ftt84.jpg
I need to parse out the post_form_id. I've tried
var value = doc.DocumentNode.SelectSingleNode("//input[#type='hidden' and #name='post_form_id']")
.Attributes["value"].Value;
but obviously won't work because it's inside the iframe form. Appreciate any help.
I would
Use the HTMLAglityPack to find the iframe location
Use the System.URI class find the absolute link of the iframe page
Open this iframe page
Use HTMLAglityPack again on the iframe page to find the required information
Related
We have a page(URL 2) which is embedded or loaded in Div element(Popup) of another page(master page) when a button is clicked on master page(URL 1).
I am not able to access the elements on this embedded page.
The firepath developer plugin shows, there are two objects (Top Window URL 1 and another with different URL 2). When I try to highlight any element with xpath locator on page 2 URL 2, its not successful as the object/document selected is Top Window. In order to access elements on page 2, the document needs to be changed.
Tried using SwitchTo method but no luck. The embedded page is niether loaded in a separate window nor in Iframe.
SwitchTo method can only be used if another window is opened or Iframe is present on page.
Does anyone have any ideas or solutions to change the document context so that all new commands are sent to this new page 2.
I am using C# bindings v2.53.
Thanks in advance.
Try to use:
driver.SwitchTo().Window(driver.WindowHandles.ToList().Last());
I got the problem and eventually answer to that.
Its really simple. Its simply working out with jquery.
{driver.executeScript("return $('body /deep/ <#yourSelector>')}
this piece of code simply draws the element from shadow DOM and which can be further used to simulate user actions... :)
I am trying to access this webpage http://www.pof.com with C# code.
I figured out that the Document element is stored in an iframe after I successfully logged in as a user and I am not familiar with how to access the document element.
All I want to do is to get the HTML format of that page which is loaded with an iframe and go to some of the links of that site.
Use following code:
document.getElementById('iframe1').contentWindow.document
or simply,
var elemVal;
if (iframeDocument) {
elemVal= iframeDocument.getElementById('#iframe1');
}
I want to assign the html content to iframe control from asp.net code behind page;
this is working fine
myIframe.Attributes.Add("src", "pathtofilewith.html");
but, i don't want to give the path of html file to display i just want to assign some html content which comes from database to iframe control.
i want some thing like this(Ashok) to be displayed in iframe control
i tried the bellow ways but nothing is succesful
myIframe.Attributes["innerHTML"] = "<h1>Thank You..</h1>";
myIframe.Attributes.Add("innerHTML", "<h1>Ashok</h1>");
A way to communicate between two different pages where one is in an IFrame on the other, is to post data using JQuery. An example is given in this StackOverflow question
It is also discussed in this other StackOverflow question
On this page, you will also find a short and simple example of how you can put content in an IFrame without using a separate web-page for it (note the lacking src attribute!).
Hope some of this helps!
You can't. That's not how an IFRAME works - it is for use with the src attribute as you've already discovered.
Perhaps you want to create a DIV instead
There is no way to insert HTML content into iframe tag directly, but you can create a page which gets the content form the database and then you can view it using iframe,
or
You can create a page for example called getContent.aspx which request value from the URL e.g. getContent.aspx?content=<h1>Thank You..</h1> and display it wherever you like, and then call it from iframe.
I know that I can access all iframes using the following properties of webbrowser:
string html = webBrowser1.Document.Window.Frames[0].WindowFrameElement.InnerText;
But I'm struggling with cross-domain restriction..
My document url is like www.subdomain1.sport.com/...
And iframes url is like www.subdimain2.sport.com/...
How to access iframes content and put some text into input tag there?
I think you must refer the following URL to get the content of IFrame which exists on cross domain.
http://codecentrix.blogspot.com/2008/02/when-ihtmlwindow2document-throws.html
I am trying to create a piece of software to more or less automate form-fillings on a webpage - and I have decided to use the WebBrowser control in System.Windows.Forms. This works great and I can easily manipulate the DOM through webbrowser.Document and so forth. However unfortunately the site that I am doing automation on has a file upload which is ran inside an iframe - and this is where I am stuck, I simply cannot work out how to be able to manipulate elements inside the DOM of the iframe.
Ideally what I'd like to do is something like:
HtmlElement iframe = browser.Document.GetElementById("iframe_id");
iframe.InnerDocument.GetElementById("file_upload_input").SetAttribute("value", "myfile.txt");
And then submit the form inside the iframe of course - however there is no InnerDocument attribute on HtmlElement as far as I can see, nor no type that I have found that I can cast HtmlElement to so that I can access the inner DOM.
How this is done?
Try using the "frames" collection instead. From MSDN:
The iframe element functions as a
document within a document, or like a
floating frame. The frames collection
provides access to the contents of an
iframe. Use the frames collection to
read or write to elements contained in
an iframe. For example, the syntax for
accessing the backgroundColor style of
the body object in an iframe is:
sColor =
document.frames("sFrameName").document.body.style.backgroundColor;