selenium webdriver is clearing out fields after sendKeys had previously populated them

前端 未结 2 1378
北海茫月
北海茫月 2021-01-13 08:25

The webpage that I\'m testing is using knockout. On other pages on our site that are not currently using knockout I\'m not having the same problem. The scenario I have is

2条回答
  •  爱一瞬间的悲伤
    2021-01-13 09:09

    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.

    The point is that knockout model updates are triggered (by default) with the change event. If it's not being executed, it's underlying model won't be up-to-date.

    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.

提交回复
热议问题