.NET | SELENIUM | Get the IWebElement clicked by left mouse. Capture all clicked elements

huangapple go评论72阅读模式
英文:

.NET | SELENIUM | Get the IWebElement clicked by left mouse. Capture all clicked elements

问题

Good evening together,

我最近几个小时一直在研究这个问题。我想要能够获取用户通过鼠标点击的所有元素(IWebElement)。我正在寻找一种像事件处理程序那样的方法。

我尝试了EventFiringWebDriver方法,但它不起作用,因为它只在以编程方式点击元素(.Click()函数)时才触发。然后我尝试了通过注入Javascript来实现,这个方法可以工作,但它只会将最后一个元素存储在一个变量中,每次点击后我必须手动检索它。

有没有一种正确的方式来处理这个问题?

我想要使用这个事件处理程序的场景是一个自动化框架,用于记录所有点击和底层元素。

问候和提前感谢。

英文:

Good evening together,

I am struggling with this problem the last couple hours. I want to be able to get all elements (IWebElement) that are being clicked by a user (with mouse). I am looking for a way to use such as a eventhandler.

I came up with the EventFiringWebDriver Method - Does not work because it only fires when an element is clicked programmatically ( .Click() - function).
Then I tried to do it with injecting Javascript. That works so far but it stores the last Element in a var and I have to retrieve it manually after each click....

Is there a way how I can handle it propperly?

The scenario I want to use this event handler is for a Automation Framework where all clicks and the underlying element is recorded.

Greetings and thanks in advance.

答案1

得分: 0

如果您能够将最后一个元素存储在一个var中,您可以在每次点击时更新同一脚本,以将所有这些元素保存到一个JS数组中。在完成测试执行后,您可以查询该变量一次以检索该数组。您甚至可以考虑使用HTML5 Web Storage或类似的方法来存储数组。

英文:

Adding as an answer since the reputation is not allowing to comment.

If you could manage to store the last element in a var, you can probably update the same script to save all such elements to a JS array during each click. After completing the test execution, you can query that variable just once to retrieve the array. You can even consider using HTML5 Web Storage or something similar to store the array.

答案2

得分: 0

我找到了一个非常棒的解决方案。有一个库/扩展适用于EventFiringWebDriver方法,它正好能够实现我想要的功能。

https://github.com/AbrahamSanders/Selenium.WebDriver.EventCapture

英文:

I found a very neat solution. There is a library/extension to the EventFiringWebDriver Method that does exactly what I want it to do.

https://github.com/AbrahamSanders/Selenium.WebDriver.EventCapture

huangapple
  • 本文由 发表于 2023年4月11日 04:36:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980526.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定