Midi
Midi

Reputation: 479

Injecting custom JS Code using Selenium Web Driver

I'm writing automated UI tests in C# using Selenium 2 Web Driver for web application written in ASP.NET and MS AJAX. I would like to "inject" custom JS code on the beginning of test which will execute every time async postback is finished. Example code below

function EndRequestHandler(sender, args)
{
   DoSomeStuff(...);
}

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

The question is how to do this using Selenium (I don't want to modify original application). This have to be compatible with IE, Firefox and Chrome drivers, so using custom profiles for Firefox is not an option (although I might be missing something here)

Upvotes: 2

Views: 7908

Answers (2)

mmcconnell1618
mmcconnell1618

Reputation: 26

If you just need to wait until all the ajax completes before continuing your Selenium test this article will help:

How to get selenium to wait for ajax response?

Upvotes: 0

TGH
TGH

Reputation: 39258

I might misunderstand what you're trying to do here, but here is a link that might illustrate what you need. Execute JavaScript using Selenium WebDriver in C#

Upvotes: 3

Related Questions