最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - Injecting custom JS Code using Selenium Web Driver - Stack Overflow

matteradmin7PV0评论

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 patible with IE, Firefox and Chrome drivers, so using custom profiles for Firefox is not an option (although I might be missing something here)

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 patible with IE, Firefox and Chrome drivers, so using custom profiles for Firefox is not an option (although I might be missing something here)

Share Improve this question asked Apr 1, 2012 at 17:51 MidiMidi 4791 gold badge5 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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#

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

How to get selenium to wait for ajax response?

Post a comment

comment list (0)

  1. No comments so far