如何在C#中实现WebDriverEventListener? [英] How to implement a WebDriverEventListener in C#?

查看:316
本文介绍了如何在C#中实现WebDriverEventListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中实现WebDriverEventListener?

在Java导入中我没问题:

I have no problem doing it in java importing:

import org.openqa.selenium.support.events.AbstractWebDriverEventListener;

但是,在C#中看不到WebDriverEventListener,我无法实现它.

However, WebDriverEventListener is not seen in C# and I cannot implement it.

推荐答案

C#中的事件侦听是通过使用该语言公开的标准事件机制来完成的.您为事件创建具有正确签名的方法,并将其附加到事件.一个示例方法如下所示:

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");
}

附加事件如下所示:

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

在事件处理程序方法中,EventArgs参数允许您检查与事件关联的属性.如果发生元素事件,则EventArgs将引用触发该事件的IWebElement.要断开事件处理程序,请使用标准的C#-=运算符.

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.

这篇关于如何在C#中实现WebDriverEventListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆