Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onchange event does not get fired on selenium type command

I am typing some value, on change do a total. But somehow, this event is not getting fired with selenium type command.

I also tried typeKey and typeAt ..But no success. Any workaround for this ?

like image 396
Jigar Shah Avatar asked Jan 14 '11 10:01

Jigar Shah


People also ask

What is Type Command in selenium?

TYPE Command TYPE sets the value of an input field, as though you typed it in.

Does selenium have record and playback?

Record and playback is one of the key features of Selenium IDE, among other features that help manual testers get a taste of automation and its benefits. Selenium IDE has a rich set of commands powered by Selenese, allowing you to record various interactions of a web app with the browser.


2 Answers

To trigger the onchange event, try adding this command in Selenium IDE:

fireEvent targetID blur

like image 139
trex Avatar answered Oct 16 '22 08:10

trex


Firefox has a bug which prevents some events from being executed while the browser window is out of focus. This could be an issue when you're running your automation tests - which might be typing even if the window is out of focus.

To fix this issue I triggered the change event "manually", injecting javascript into my tests.:

//suppose "element" is an input field
element.sendKeys("value");
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("$(arguments[0]).change();", element);

As you might have noticed, I'm using jQuery to trigger the change event. If you're not using jQuery on your app, you can check here how to trigger it using vanilla javascript.

Hope that helps somebody.

like image 7
Marlon Bernardes Avatar answered Oct 16 '22 09:10

Marlon Bernardes