onchange event does not get fired on selenium type command

前端 未结 8 2115
予麋鹿
予麋鹿 2020-12-17 21:47

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 succe

8条回答
  •  天命终不由人
    2020-12-17 22:04

    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.

提交回复
热议问题