如何在 C# 中实现 WebDriverEventListener?

How to implement a WebDriverEventListener in C#?(如何在 C# 中实现 WebDriverEventListener?)
本文介绍了如何在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)