C# und interet explorer automation
Hallo, ich arbeite in einem internet explorer-Automatisierungs-und das ist Neuland für mich, ich erhalte eine Fehler mit einem festgelegten, nicht gelungen, kann Sie sehen, was ich falsch mache?
Unable to cast COM object of type 'System.__ComObject' interface-Typs " mshtml.HTMLElementCollection'. Dieser Vorgang ist fehlgeschlagen, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit IID '{3050F56B-98B5-11CF-BB82-00AA00BDCE0B}' konnte aufgrund des folgenden Fehler: Schnittstelle Nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).
der code ist:
namespace IEAutomation {
///<summary>
///Summary description for IEDriverTest.
///</summary>
///
using mshtml;
using System.Threading;
using System;
using SHDocVw;
using System.Collections;
using MySql.Data.MySqlClient;
public class IEDriverTest {
public IEDriverTest() {
}
public void TestGoogle() {
object o = null;
SHDocVw.InternetExplorer ie = new
SHDocVw.InternetExplorerClass();
WebBrowser wb = (WebBrowser)ie;
wb.Visible = true;
//Do anything else with the window here that you wish
wb.Navigate("https://adwords.google.co.uk/um/Logout", ref o, ref o, ref o, ref o);
while (wb.Busy) { Thread.Sleep(100); }
HTMLDocument document = ((HTMLDocument)wb.Document);
IHTMLElement element = document.getElementById("Email");
HTMLInputElementClass email = (HTMLInputElementClass)element;
email.value = "[email protected]";
email = null;
element = document.getElementById("Passwd");
HTMLInputElementClass pass = (HTMLInputElementClass)element;
pass.value = "pass";
pass = null;
element = document.getElementById("signIn");
HTMLInputElementClass subm = (HTMLInputElementClass)element;
subm.click();
subm = null;
while (wb.Busy) { Thread.Sleep(100); }
wb.Navigate("https://adwords.google.co.uk/o/Targeting/Explorer?", ref o, ref o, ref o, ref o);
while (wb.Busy) { Thread.Sleep(100); }
string connString = "SERVER=localhost;" +
"DATABASE=test;" +
"UID=root;";
//create your mySQL connection
MySqlConnection cnMySQL = new MySqlConnection(connString);
//create your mySql command object
MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
//create your mySQL reeader object
MySqlDataReader reader;
//open the mySQL connection
cnMySQL.Open();
int j=1;
cmdMySQL.CommandText="SELECT * FROM `emails1` WHERE `send`>'" + j + "' order by `send` asc limit 0,1";
reader = cmdMySQL.ExecuteReader();
reader.Read();
j = (int) reader.GetValue(1);
HTMLElementCollection col = default(HTMLElementCollection);
document = ((HTMLDocument)wb.Document);
col = (HTMLElementCollection)document.getElementsByTagName("textarea");
//the error happens here in this typecast
Console.WriteLine(j);
wb.Quit();
}
}
}
InformationsquelleAutor Evan | 2012-04-06
Du musst angemeldet sein, um einen Kommentar abzugeben.
Versuchen Umwandlung in ein
IHTMLElementCollection
statt.oder deklarieren col als IHTMLElementCollection
InformationsquelleAutor Roger Stewart