El selenio reacciona a los eventos.

I'm currently using the latest version of Selenium and its .net bindings to perform some tests. Unfortunately I have to simulate some reaction that happens at a variable time and can only be performed within a very limited time interval, and polling the DOM continuously is not fast enough. Is there a way for Selenium to hook to DOM events so that I could intercept the events I'm interested into in my code? If so, sample .net code would be greatly appreciated.

Gracias por adelantado

P.S.: I'm largely indifferent to the browser, however a solution that works in Chrome would be preferred

preguntado el 08 de noviembre de 11 a las 12:11

Depending on your browser this may be a problem of the locator type and browser type and that's why you can't poll the DOM. -

I think he can poll the DOM, he is just looking for a solution that doesn't require polling -

@prestomanifesto the OP said that polling the DOM wasn't fast enough hence my statement about the browser type. Case and point I ran a benchmark test with Selenium 2 Webdriver C# and found that finding an element by ID took 198ms in firefox and 308ms in IE (that's the average of 5 tries for each browser. But The CssSelector or Xpath were 7ms for Firefox and 38ms for IE again the average of 5 tries for each. So if he's polling the DOM by ID in IE that may be slower than the response time needed. -

I'm using binding by ID, thanks for suggesting that XPath might be quicker. I suppose chrome would outperform both FF and IE, and if that's not the case I'd still rather stick with it as the rest of the page loading and interactions would be faster... -

1 Respuestas

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

Probablemente quieras usar RunScript() to hook the event you want, and then have your test script wait until the event has had enough time to fire, then you can use GetEval() to retrieve or verify the results of the event handler.

respondido 08 nov., 11:18

Here's a link to an example of what @Ross Patterson mentions swtestacademy.com/selenium-wait-javascript-angular-ajax - Tomas Hesse

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.