 |

|
Thank you for your work! It's very helpful!
How can I set the Zoom to 100%.... Our tests fail if it's anything but 100%
|
|
|
|

|
this causing error because IE takes different time to load up i mean if IE is already open it will take less time or if IE is not open it will take long time.. so no fix time tht how much time thread should sleep so i got a solution for it
just change..
Process m_Proc = Process.Start("IExplore.exe"); to
Process m_Proc = Process.Start("IExplore.exe", "-nomerge www.google.com");
and Thread.Sleep(500) to Thread.Sleep(5000)
so now it will open new IE in new browser and will wait 5 sec to get it complete ...
it helped me hope it helps all...
|
|
|
|

|
i get this error when i run the code.
System.InvalidCastException was unhandled
Message=Specified cast is not valid.
Source=Interop.SHDocVw
on this line
if(Browser.HWND == (int)m_Proc.MainWindowHandle)
kindly help
|
|
|
|

|
it helped a lot
|
|
|
|

|
how to click button if button has no ID and no Name and just value
say example ::
<INPUT TYPE="SUBMIT" VALUE="Login" TABINDEX=4>;
here button has no name and no ID.
it has just value.
any help appriciated.
Regards,
Chetan..
|
|
|
|

|
IE 8 introduces something called "Loosely Coupled IE" (LCIE), which launches extra processes for use in additional tabs and such. If you try to use this code and launch an IE window after an existing one is already open this code will not work. When attempting to spawn the new process and navigate to a page, it pops up with the error 'Process has exited, so the requested information is not available.' I had to resolve this by changing a registry setting
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
then add TabProcGrowth as a new DWord 32 bit value, and set it to '0'. Restart all instances of IE. It should work after that and you can open subsequent IE processes at any time, no matter how many previous ones are open.
Hopefully this will help someone else.
|
|
|
|

|
Thanks, this helped a lot!
|
|
|
|

|
That article really helped me a lot. I was facing problem to insert data in the text box and click button. It worked fine in my local computer where VS is installed but for the computers where VS is not installed it shown exception to convert _Comobject to mshtml.HTMLInputElementClass.
So I modified a bit. here is the modified file http://www.box.net/shared/zymkn7x5yv
Anyway thanks a lot for the article.Ashrafur Rahaman
|
|
|
|

|
Thanks.
Save a lot of my time Ashrafur Rahaman
|
|
|
|

|
I have my code to automate IE working, but it could be made faster by eliminating all of the extraneous downloading - images, JavaScript, Flash advertisements, etc. Is there a way to disable some or all of these items on an instance by instance basis? For example, for project 1, disable images and flash and for Project 2, disable JavaScript and flash? So far, all of my attempts to do so enable images for example in all browser sessions - even those that are not automated. (It changes all Internet Explorer options globally.)
Thanks!
|
|
|
|

|
First thank you for this useful article.
I have a problem in working with IE 7 +. My program does not work in IE 7. Is it normal?
So what should we do in IE 7?(For example IE 7 has multiple tabs, how to select one tab, do i need another dll?)
|
|
|
|

|
I am confused by the same problem. Anyone can help??
|
|
|
|

|
the core mshtml.dll maybe different
hope you can find the reason
I want to make one
if success ,I will share it to all you.
|
|
|
|

|
I test the code above and found the same problem.
The way to solve this is to change code below
Process m_Proc = Process.Start("IExplore.exe");
Thread.Sleep(500); to Thread.Sleep(3000);
Maybe it's because the ie hadn't load. So we need to wait longer.
There is also some way to test whether the ie has loaded.
Whoever interested please read the article:
http://www.colblog.net/node/205
|
|
|
|

|
God bless you all, this information helped me a lot
|
|
|
|

|
Hi,
I think you should replace the following line (bolded text)
private IHTMLElement GetElementByValueOnce(string tagName, string elementValue)
{
HTMLDocument document = ((HTMLDocument)IE.Document);
IHTMLElementCollection tags = document.getElementsByTagName(tagName);
IEnumerator enumerator = tags.GetEnumerator();
while (enumerator.MoveNext())
{
IHTMLElement element = (IHTMLElement)enumerator.Current;
if (element.innerText == elementValue)
{
return element;
}
}
return null;
}
with this
private IHTMLElement GetElementByValueOnce(string tagName, string elementValue) {
HTMLDocument document = ((HTMLDocument) IE.Document);
IHTMLElementCollection tags = document.getElementsByTagName(tagName);
IEnumerator enumerator = tags.GetEnumerator();
while (enumerator.MoveNext()) {
IHTMLElement element = (IHTMLElement) enumerator.Current;
if (element.getAttribute("Value", 0).ToString().Equals(elementValue)) {
return element;
}
}
return null;
}
Noname_vn
|
|
|
|

|
Also,
Another possible method
public void FormSubmit(string formID)
{
mshtml.IHTMLFormElement form = (mshtml.IHTMLFormElement)GetElementById(formID);
isDocumentComplete = false;
form.submit();
WaitForComplete();
}
|
|
|
|

|
Hi,
It is working fine in IE6
but in IE7 it is not opening the new I Explorer window
|
|
|
|
|
|

|
It's great,thx
my blog:
http://blog.ppcode.com
|
|
|
|

|
i want to automatic print a webpage. With this technology. how can i do that ?
Thank in advance
|
|
|
|

|
It can be easily done with SWExplorerAutomation (SWEA) from http://webius.net.
The print code example using SWEA:
public static void explorerManager_DialogActivated(object sender, SWExplorerAutomation.Client.DialogScene dialogScene) {
if (dialogScene.Title == "Print") {
if (dialogScene.ControlExists("Print"))
dialogScene.DialogButton(("Print")).Click();
}
public static void Main() {
ExplorerManager explorerManager = new ExplorerManager();
SWExplorerAutomation.Client.Scene scene;
explorerManager.DialogActivated += new SWExplorerAutomation.Client.DialogActivatedEventHandler (SWExplorerAutomationExamples.CodeTemplate.explorerManager_DialogActivated);
explorerManager.LoadProject("..\\..\\PrintDialog.htp");
explorerManager.Connect();
explorerManager.Navigate("http://webiussoft.com/");
scene = explorerManager["Scene_0"];
scene.WaitForActive(30000);
scene.HtmlContent("HtmlContent_0").Invoke("window.print();",ControlActionType.InvokePageScript);
explorerManager.DisconnectAndClose();
}
AlexF
|
|
|
|
|

|
You can print to the default-printer by using:
Object em = null;
driver.IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref em, ref em);
(Just make IE public in IEDriver or add a function to IEDriver itself).
|
|
|
|

|
How about number of copies??
|
|
|
|

|
This code is very good, but it's not fully featured (that's not a critic, just a fact). For example, it does not have an option to close the IE opened.
I found that :
http://watin.sourceforge.net/
It's free, opensource, and still supported.
|
|
|
|

|
Watin does not support Firefox, or has this changed meanwhile?
|
|
|
|

|
Yes, I don't think watin supports FF.
The point of Watin is, I think, to run automated tests which are not depending on the browser used to fail or not.
There was a mozilla activeX, but I never got far with it. The one I can found seems to be abandoned http://www.iol.ie/~locka/mozilla/mozilla.htm[^]
|
|
|
|

|
For more advanced alternative and integrated with Visual Studio,
Look InCisif.net and their main screen cast.
F.Torres
|
|
|
|

|
When i click on the login button on the page, which i am trying to automate. I am getting a security alert dialog, how to automate this?.
|
|
|
|

|
InCisif.net is a functional web testing for the .NET languages which also support JavaScript and Windows system dialog like the security alert, file download, user login...
www.InCisif.net
Frederic Torres
www.InCisif.net
Web Testing With C# Or VB.NET
|
|
|
|

|
Hi,
I am trying to use this code for some application of mine. However, this code works fine, if I run it on my local server, through the same machine. However, when I load this on my remote web-server and try to access through http, it throws an error and does not open the explorer. Can anybody help or provide me a patch.
Thanks
Atul Jain
|
|
|
|

|
IE requires an user profile to be loaded. The Web server user account doesn't have an user profile.
You can try SWExplorerAutomation (SWEA) from http://webius.net. SWEA allows to run IE under user account different from Web server account.
AlexF
|
|
|
|

|
I have used this tool with VS2003 and now I am trying to upgrade to VS2005, but now I get this error every time the IEDriver constructor executes.
What it seams is that the foreach loop does not finds the WindowHandel index value matching the Browser.HWND. At the end of loop the _IE variable will never be instantiated. Can you give me any advise in how to work this problem.
|
|
|
|

|
I encountered the same problem in VS 2008 and resolved it by increasing the sleep period in the constructor.
|
|
|
|

|
I have a severe problem with frames and security.
When I try to access the document in a given frame I get a security exception. I get this exception under the Visual Studio debugger for every property of a frame. I'd like to be able to solve this problem right away --- because ---
I have a substatial amount of code written called DomDriver which sits over the top of IEDriver and allows you to drive IEDriver in many more ways than the original code provides. For instance I have methods that allow you to click an anchor or button based on the value of one of it's attributes, or based upon the innerHTML, outHTML or text - exact match, contains, begins with and ends with. Lookup and element using the same methods.
I also have incorporated code to capture an existing window (someone else's code project) into this project. You can also retrict the element lookups to a single frame and / or frameset.
If anyone knows how to get around the frames + security problem I'd be willing to donate my code to this project (and I think it would benefit everyone).
Thanks
|
|
|
|

|
Could you post a website where you got this problem?
Thanks.
|
|
|
|

|
Hi,
First of all a huge thank you for the code, it has been a fantastic help.
But I have sometimes have the same problem as the one mentioned by yousefk, if i rollout the programm on another machine. On some machines it is OK, but on other machines the following error is thrown whenn a new instance of IEDriver is created:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error
at SHDocVw.IWebBrowser2.get_HWND()
at IEAutomation.IEDriver..ctor()
I install the progamm using a asp.net setup programm, and it copies the files IEDriver.dll, Interop.SHDocVw.dll and Microsoft.mshtml.dll with my .exe. The other machine has exactly the same OS (win xp 2002 sp 2) and Internet Explorer (6.0.2900 SP 2) as my developer machine and the other PC where it does run correctly.
Anybody has any idea what the problem might be? Any hints would be greatly appreciated.
Thanks
|
|
|
|

|
After reading the other comments, i found the solution in texios post somewhere down.
Changing the constructor did the job, I paste his comment down here:
When I tried to create an instance of IEDriver an unknown Exception was thrown. I corrected the problem by changing the constructor from:
public IEDriver() {
Process m_Proc = Process.Start("IExplore.exe");
Thread.Sleep(500);
_IE = null;
ShellWindows m_IEFoundBrowsers = new ShellWindowsClass();
foreach(InternetExplorer Browser in m_IEFoundBrowsers) {
if(Browser.HWND == (int)m_Proc.MainWindowHandle) {
_IE = Browser;
break;
}
}
IE.Visible = true;
IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);
}
into:
public IEDriver() {
_IE = new InternetExplorerClass();
IE.Visible = true;
IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);
}
Works the same way and is much easier I think. Anyway thank you for spending a lot of time on this IE Driver. This is very very useful piece of code.
|
|
|
|

|
Blottie, you rock my socks. Nice fix. I had the same problem on Vista.
|
|
|
|

|
Maybe this is to late to answer your question
Check internet explorer, internet options, security tab, uncheck enable protected mode (IE7)
In the case of IE6 another security option might be the cause of the problem.
|
|
|
|

|
Browser.HWND throw the following exception why ?:
{"Unspecified error" }
inside:
public IEDriver() {
if(Browser.HWND == (int)m_Proc.MainWindowHandle) {
_IE = Browser;
break;
}
what's wrong ?
Markos
|
|
|
|

|
See my post one thread up, it has a solution. Seems to be the same problem.
|
|
|
|

|
You can also try SWExplorerAutomation (SWEA) from Webius http://webiussoft.com[^]. SWEA automates Web Browser.The program creates an automation API for any Web application developed with HTML, DHTML or AJAX. The Web application becomes programmatically accessible from any .NET language.
SWEA API provides access to Web application controls and content. The API is generated using SWEA Visual Designer. SWEA Visual Designer helps create programmable objects from Web page content.
AlexF
|
|
|
|

|
You can also try iMacros, this is what we are using for quite some time now.
Unlike IEDriver and SWExplorerAutomation, it can also automate and test Flash, Flex, Java and Silverlight applets. And it works with Firefox, too.
http://www.iopus.com/imacros/component.htm[^]
Hope this helps,
Michael
|
|
|
|

|
Hi,
I have a problem, i need login to my webpage throught windows services and a i can't access to property HtmlDocument.parentWindow. in windows forms applications this works.
This error appear me
System.RuntimeType.ForwardCallToInvokeMember
thanks
|
|
|
|

|
I added static methods to the IEDriver class to capture and control an existing Internet Explorer instance. This can be used to control those pesky popup windows. Here is the code - enjoy!
public static IEDriver FromWindow(string title, int delay, int count)
{
WindowList wl = new WindowList();
WindowInfo wi = null;
count = count > 0 ? count : 1;
for (int j = 0; j < count && wi == null; j++)
{
wl.RefreshDesktopWindows();
for (int i = 0; i < wl.Count; i++)
{
if (wl[i].title.ToLower().Contains(title.ToLower()))
{
wi = wl[i];
break;
}
}
if (delay>0)
Thread.Sleep(delay);
}
if (wi == null)
return null;
IEDriver result = new IEDriver(wi.processID);
result.Open();
return result;
}
And the window list class...
public class WindowInfo
{
public IntPtr hWnd = IntPtr.Zero;
public IntPtr lParam = IntPtr.Zero;
public string title=null;
public uint processID=0;
}
public class WindowList : List<WindowInfo>
{
int _hWnd;
public WindowList(int hWnd)
: base()
{
_hWnd = hWnd;
}
public WindowList()
: base()
{
_hWnd = 0;
}
public int hWnd
{
get { return _hWnd; }
set { _hWnd = value; }
}
public int FindWindow(string windowName, bool wait)
{
IntPtr hWnd = WinAPI.FindWindow(null, windowName);
IntPtr hZip = new IntPtr(0);
while (wait && hWnd.Equals(hZip))
{
System.Threading.Thread.Sleep(500);
hWnd = WinAPI.FindWindow(null, windowName);
}
return hWnd.ToInt32();
}
public int RefreshChildWindows()
{
this.Clear();
WinAPI.EnumChildWindows(new IntPtr(_hWnd), ThisEnumWindows, new IntPtr(0));
return this.Count;
}
public int RefreshWindows()
{
this.Clear();
WinAPI.EnumWindows(ThisEnumWindows, new IntPtr(0));
return this.Count;
}
public int RefreshDesktopWindows()
{
return RefreshDesktopWindows(0);
}
public int RefreshDesktopWindows(int desktop)
{
this.Clear();
WinAPI.EnumDesktopWindows(new IntPtr(desktop), ThisEnumWindows, new IntPtr(0));
return this.Count;
}
private bool ThisEnumWindows(IntPtr hWnd, IntPtr lParam)
{
int len = WinAPI.GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(len+1);
WindowInfo ci = new WindowInfo();
ci.hWnd = hWnd;
ci.lParam = lParam;
WinAPI.GetWindowText(hWnd, sb, sb.Capacity);
ci.title = sb.ToString();
if (ci.title.Length > 1)
{
if (ci.title.Contains("Microsoft Internet Explorer"))
{
WinAPI.GetWindowThreadProcessId(hWnd, out ci.processID);
this.Add(ci);
}
}
return true;
}
}
And lastly the WinAPI class
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
public class WinAPI
{
#region Wind32API
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint lpdwProcessId);
[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumWindowsProc lpEnumFunc, IntPtr lParam);
#endregion
}
You know neither the day nor the hour.
|
|
|
|

|
Sorry,
I forgot to include the overloaded constructor I added that uses a process id - here is the code for that. One thing to remember though is that you'll need to add your own logic to not ALWAYS terminate and close the window - there are some cases (as in popups) where you do not want to do this in the class destructor. I also added a boolean property named TerminateOnDestroy that governs this behavior. Easy enough to implement on your own.
Overloaded Constructor
public IEDriver(uint processID)
{
mProcess = Process.GetProcessById((int)processID);
}
You know neither the day nor the hour.
|
|
|
|

|
Thankyou so much for sharing
Just for the sake of accuracy, I'm listing here below some missing parts in your code:
- FromWindow -> looking at one of the last rows there is the "result.Open();" call, but the Open method doesn't exists
- In your added constructor the mProcess variable is undefined
|
|
|
|
 |