How to implement a WebDriverEventListener in C#?

后端 未结 5 824
感情败类
感情败类 2021-01-01 06:01

How to implement WebDriverEventListener in C#?

I have no problem doing it in java importing:

import org.openqa.selenium.support.events.A         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 06:33

    Event listening in the C# is accomplished by using the standard event mechanism exposed by the language. You create a method with the correct signature for the event, and attach it to the event. An example method would look like this:

    void MyElementClickedHandler(object sender, WebElementEventArgs e)
    {
        Console.WriteLine("Clicked");
    }
    

    Attaching the event would look something like this:

    // Assumes driver is a properly created
    // IWebDriver instance. 
    IWebDriver eventDriver = new EventFiringWebDriver(driver);
    eventDriver.ElementClicked += new EventHandler(MyElementClickedHandler);
    

    Inside the event handler method, the EventArgs parameter allows you to examine attributes associated with the event. In the case of an element event, the EventArgs will have a reference to the IWebElement the event fired on. To disconnect the event handler, you use the standard C# -= operator.

提交回复
热议问题