-2

I am new to programming. I am using window form in VisualStudio C#. My problem is after clicking the first button in my Window Form, It opens the browser and go to Url that I want to login and after that when I click the Second button on my Window Form, it doesn't run the second block of codes. I don't get any error message. Can anyone help me because I am totally a beginner. Thank you so much in advance!

public partial class Form1 : Form
{
    IWebDriver driver = null;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        driver = new FirefoxDriver();
        driver.Url = "https://accounts.google.com/ServiceLogin";    
        driver.Manage().Window.Maximize();

    }

    private void button2_Click(object sender, EventArgs e)
    {
        driver.Url = "https://accounts.google.com/ServiceLogin";

        var email = driver.FindElement(By.Id("Email"));
        email.SendKeys("-------------");
        var password = driver.FindElement(By.Id("Passwd"));
        password.SendKeys("---------");
        password.FindElement(By.Id("signIn"));
4

1 回答 1

0

添加button2.Click += button2_Click;到您的 Form 构造函数,就在InitializeComponent();. 此行将事件处理程序添加button2_ClickButton.Click.button2

通常,这种东西会为你做设计师。如果您喜欢这种方式,请转到表单的预览页面,然后到属性管理器,单击闪电“事件”并双击您想要的事件,在这种情况下Click。完成此操作后,将生成 button2 单击事件处理程序的方法体。

于 2015-03-06T15:28:16.723 回答