473,473 Members | 1,906 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MSHTM: Howto access the elements within an <IFRAME>

I am using the Webbrowser control in VS 2005 C# Express to automate the
navigation of pages on a partner's web site. The first page contains
an <IFRAME> element:

<iframe style='width:40; height:40'; align='center' marginwidth='0'
marginheight='0'
scrolling='no' frameborder='0' id='xyzlogin' name='xyzlogin'
src='https://www.xyzcorp.com/accounts/ServiceLogin'>
</iframe>

Within that frame I need to access these three elements:

<input type="text" name="Email" value="" class="xyz le val" id="Email"
size="18">
<input type="password" name="Passwd" class="xyz le val" id="Passwd"
size="18">
<input type="submit" name="null" value="Sign in" class="xyz le button"

so I can programmatically: 1)enter the user ID and password, 2)click
the 'Sign in' button.

I thought maybe Webbrowser.Document.Window.Frames would be the way to
go but that did not seem to work (sorry, I'm not at my development
environment right now or I would provide more detail).

Frames is an HtmlWindowCollection. An HtmlWindow has a Document member
which is an HTMLDocument. So, would this work:

-Look through the Frames collection until a HtmlWindow named 'xyzlogin'
is found.
-Get the Document member for that window and extract the following
HTMLElements by ID: Email, Passwd.
-Set the InnerText properties for these elements.
-Find the button element (how? it does not have a valid name or id)
-Use InvokeMember("Click") to click the button.

May 10 '06 #1
3 24069
cweeks,

Yep, that's exactly how I would do it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"cweeks" <cw*********@yahoo.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
I am using the Webbrowser control in VS 2005 C# Express to automate the
navigation of pages on a partner's web site. The first page contains
an <IFRAME> element:

<iframe style='width:40; height:40'; align='center' marginwidth='0'
marginheight='0'
scrolling='no' frameborder='0' id='xyzlogin' name='xyzlogin'
src='https://www.xyzcorp.com/accounts/ServiceLogin'>
</iframe>

Within that frame I need to access these three elements:

<input type="text" name="Email" value="" class="xyz le val" id="Email"
size="18">
<input type="password" name="Passwd" class="xyz le val" id="Passwd"
size="18">
<input type="submit" name="null" value="Sign in" class="xyz le button"

so I can programmatically: 1)enter the user ID and password, 2)click
the 'Sign in' button.

I thought maybe Webbrowser.Document.Window.Frames would be the way to
go but that did not seem to work (sorry, I'm not at my development
environment right now or I would provide more detail).

Frames is an HtmlWindowCollection. An HtmlWindow has a Document member
which is an HTMLDocument. So, would this work:

-Look through the Frames collection until a HtmlWindow named 'xyzlogin'
is found.
-Get the Document member for that window and extract the following
HTMLElements by ID: Email, Passwd.
-Set the InnerText properties for these elements.
-Find the button element (how? it does not have a valid name or id)
-Use InvokeMember("Click") to click the button.

May 10 '06 #2
Well, nothing is ever as easy as it appears or as it should be, is it?

Here's a snippet of the code:

-----
HtmlElement frameElement = null;
HtmlWindow docWindow = webBrowser1.Document.Window;
bool bLoginAttempted = false;

foreach (HtmlWindow frameWindow in docWindow.Frames)
-----

I can see in the debugger that the Frames collection has 2 elements.
But the frameWindow object does not have any valid value in any of the
members. In the debugger the value for the Document member, for
example, says:

'frameWindow.Document' threw an exception of type
'System.UnauthorizedAccessException' System.Windows.Forms.HtmlDocument
{System.UnauthorizedAccessException}

What causes this? Why can't I just access each frame as a simple
HtmlElement object?

May 10 '06 #3
Apparently I have some things to learn about processing HTML frames.

"Accessing Frames in the Managed HTML Document Object Model"
http://tinyurl.com/q7mx3

"About Cross-Frame Scripting and Security"
http://tinyurl.com/o0gp

My simple solution is to simply navigate directly to the URL referenced
in the <IFRAME> tag and process the returned document. That enables
me, in this case at least, to process the document as a top-level
document.

May 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kirk | last post by:
Is it possible to stop horizontal scrolling whilst still maintaining vertical scrolling within an <IFRAME> ? Within each page of my site I have an IFRAME for content. For some pages there is...
1
by: O.J. Tibi | last post by:
hi guys, i was wondering if you could help me with a small problem. i need to have an <iframe> to behave like a <div>, in such a manner that: 1) the <iframe> should have its own display space,...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
2
by: chaitatp | last post by:
Hi guys, I have posted a similar question before but this post has some different. The similar link is: ...
5
by: Grzesiek | last post by:
Hi! I have created page which contains some menu buttons and <iframe> with sub-page. Each menu action on the master web site should change content of iframe (by changing src attribute). But how to...
1
by: tilt | last post by:
Hello, I use an object element to replace the iframe element in ie, like this: <object id="x_obj" data="http://.../" type="text/html"> <iframe name="x_if" id="x_if"...
0
by: diver | last post by:
I was using an <iframe> to load a website within my .aspx page. When the user "logged out", I called a javascript break out function to breakout of the frame and load the appropriate page when...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.