views:

530

answers:

2

We have web ui project in MVC and for automated testing we are using Selenium, its a brilliant tool. But I am facing some problem in raising events with Selenium.

Scenario: I have a textbox which expects +ve value and bubbles up an error (javascript) when entered any -ve value and we hit tab from that textbox or clicked outside anywhere on the page.

It works fine with normal user interaction with the website but when using selenium I am not able achieve this behaviour. I am putting some text with Selenium.Type('elementId',-ve value) the event doesn't gets fired and the error doesnt bubbles up.

I tried using FireEvent("textboxId","blur") but its not working. The only work around is Focus on the textbox, add some value, use FireEvent("textbox","blur") and then Focus on some other textbox.

Has anyone got any idea to resolve this?

+1  A: 

Your workaround doesn't sound like a bad option. When you focus the field, then change the content and then you blur (focusing in other field) is the exact same interaction the user does.

A different alternative (I still prefer the one focusing on other field) is to use getEval to trigger the javascript function that validates the field. You can check this tutorial on how to do that: http://www.theautomatedtester.co.uk/seleniumtraining/Selenium%5FJavaScript.htm

Santi
A: 

I was able to get this working with the Java client in Selenium RC by calling

  • type("id=textboxid", "newValue");

and then

  • fireEvent("id=textboxid", "blur");

Did you get any indication as to whether the "blur" event was being fired at all? I wonder if maybe the locator wasn't quite working right to fire the event.

Whatever little tricks you need to pull to get it working, to avoid doing this for every field, you should either wrap your 2-3 calls in a function if using an RC client, or register some user extensions to do it in one step if you're using the Selenium IDE.

Chris Jaynes