I've been trying to write an aplication to automatically log me in to facebook, pointless i know but it's a step to a greater goal. Anyway, here's the sticking point:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SHDocVw;
namespace SpamThis
{
public partial class Form1 : Form
{
string UserNames = "";
string Passwords = "";
InternetExplorer Browser;
HtmlDocument Doc;
public Form1()
{
InitializeComponent();
}
private void UserName_TextChanged(object sender, EventArgs e)
{
UserNames = UserName.Text;
}
private void Password_TextChanged(object sender, EventArgs e)
{
Passwords = Password.Text;
}
private void Login_Click(object sender, EventArgs e)
{
Browser = new InternetExplorer();
object o = null;
Browser.Visible = true;
Browser.AddressBar = false;
Browser.Navigate("http://www.facebook.com/", ref o, ref o, ref o, ref o);
while (Browser.Busy)
{
}
Doc.GetElementById("reg_email__").SetAttribute("reg_email__", UserNames);
}
}
}
The line highlighted in red gives me this error: "Object reference not set to an instance of an object."
And then when i try adding this line just above it: Doc = (HtmlDocument)Browser.Document;
it says that i can not convert to this type. How do i retrieve and edit the instance of IE's html document?
Is this the correct way to implement this code? Can anyone help?
Much appreciated
Loading
Samuel Amantea CollinsPosted Jul 8, 2010, 3:49 PM
Browser = new InternetExplorer();
object o = null;
Browser.Visible = true;
Browser.AddressBar = false;
Browser.Navigate("http://www.facebook.com/", ref o, ref o, ref o, ref o);
while (Browser.Busy)
{
}
Doc = Browser.Document as HtmlDocument;
if (Browser.Document != null)
Doc.GetElementById("reg_email__").SetAttribute("reg_email__", sUserName);
I still now get the error: "Object reference not set to an instance of an object."
for the line highlighted in red. Please can someone help? I've been banging my head up against the wall for ages. I've read all the documentation for these classes.
Samuel Amantea CollinsPosted Jul 8, 2010, 2:39 PM
Amit ChoudharyPosted Jul 8, 2010, 2:25 AM
try to read the API first for your Doc Class in "SHDocVw;" namespace.
then you'll find the solution why this object isn't get initialised.
Please mark "Do you like this post" if it helps you.