Selenium reacts to events

I am currently using the latest version of Selenium and its .net bindings to run some tests. Unfortunately, I have to model some reaction that occurs in variable time and can only be performed for a very limited time interval, and the DOM poll is constantly not fast enough. Is there a way for Selenium to connect to DOM events so that I can intercept the events that interest me in my code? If so, a .net code sample would be greatly appreciated.

Thank you in advance

PS: I'm pretty much indifferent to the browser, however a solution that works in Chrome would be preferable

+4
source share
2 answers

There is a good idea on how to implement event listeners for Webdriver Selenium here: http://blog.simon-reekie.me/2011/05/21/logging-selenium-2-events-in-twist/

+1
source

Your only hope for this is to do it in JavaScript. You can run arbitrary JavaScript code using ISelenium.GetEval() or ISelenium.RunScript() . GetEval() will execute the code synchronously and return the value of the last expression in the block. RunScript() actually build a new <SCRIPT> element in the DOM with your code, which will cause the browser to run it asynchronously, waiting for the JavaScript engine to work (i.e., at least after the RunScript() command completes).

You probably want to use RunScript() to hook the event you want, and then run a test script until the event has enough time to fire, then you can use GetEval() to retrieve or verify the results of the event handler.

+2
source

Source: https://habr.com/ru/post/1380169/


All Articles