Bonjour ,
j'ai un probleme avec un code sous visual studio , qui fonctionne tres bien lorsque je met des breakpoints mais qui me met une COMexception des que je lance le programme normalement.
L'erreur est la suivante :
"System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.\r\n at SHDocVw.InternetExplorerClass.get_Document()\r\n at _Default.test() in c:\\Documents\\Visual Studio 2005\\WebSites\\WebSite8\\Default.aspx.cs:line 43"
La ligne qui pause probleme dans mon code est la suivante :
myDoc = (HTMLDocument)iexplorer.Document;
Il semblerait que l'on puisse fixer ce probleme avec CoInitializeSecurity mais je ne sais pas m'en servir .
Voici le code entier :
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using mshtml;
using SHDocVw;
public partial class _Default : System.Web.UI.Page
{
public void test()
{
String errorMsg;
InternetExplorer iexplorer;
HTMLDocument myDoc;
iexplorer = new InternetExplorerClass();
object o = null;
iexplorer.Navigate("https://********", ref o, ref o, ref o, ref o);
iexplorer.Visible = true;
try
{
myDoc = new HTMLDocumentClass();
myDoc = (HTMLDocument)iexplorer.Document;
HTMLInputElement otxtSearchBox1 = (HTMLInputElement)myDoc.all.item("login_username", 0);
otxtSearchBox1.value = "****";
HTMLInputElement otxtSearchBox = (HTMLInputElement)myDoc.all.item("login_password", 0);
COMException te = new COMException();
otxtSearchBox.value = "****";
otxtSearchBox.form.submit();
}
catch (Exception ex)
{
errorMsg = ex.ToString();
}
Merci d'avance pour votre aide .
Alexis,
Partager