これは私のProgram.csです
private void button2_Click(object sender, EventArgs e)
{
InputSimulator IS = new InputSimulator();
IS.SimulateTextInput("login", "username");
IS.SimulateTextInput("lpass", "password");
IS.SimulateButtonClick("login");
}
これは私のInputSimulator.csです
namespace Functions
{
class InputSimulator
{
public void SimulateTextInput(string attName, string attValue)
{
Form1 mainForm = new Form1();
HtmlElementCollection col = mainForm.webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement element in col)
{
if (element.GetAttribute("name").Equals(attName))
{
element.SetAttribute("value", attValue);
}
}
}
public void SimulateButtonClick(string attName)
{
Form1 mainForm = new Form1();
HtmlElementCollection col = mainForm.webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement element in col)
{
if (element.GetAttribute("value").Equals(attName))
{
element.InvokeMember("click");
}
}
}
}
}
何らかの理由でNullReferenceExceptionが発生し、直接エラーが発生しないため、何が間違っているのか理解できないようです。それがうまくいかないのは、ボタンをクリックしてから次の行をクリックしたときです。
HtmlElementCollection col = mainForm.webBrowser1.Document.GetElementsByTagName("input");
誰かが私が間違っていることを知っていますか?