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

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

问题描述

如何在C#中实现WebDriverEventListener?

我在java导入中没有问题:

I have no problem doing it in java importing:

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

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

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天全站免登陆