onchange event does not get fired on selenium type command

前端 未结 8 2081
予麋鹿
予麋鹿 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:01

    It looks like the "sendKeys" command was implemented to rectify this:

    https://code.google.com/p/selenium/issues/detail?id=5451

    This worked for me.

    <tr>
        <td>sendKeys</td>
        <td>id=Quantity</td>
        <td>Type stuff here</td>
    </tr>
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-17 22:08

    If you're using Selenium 1.x, there is a fireEvent command that you can use to manually trigger the onChange event after typing in the value. Maybe that would solve your problem?

    0 讨论(0)
  • 2020-12-17 22:16

    This worked for me in IDE do the following 3 commands in order

    Typekeys   targetID    input
    FireEvent  targetID    focus
    Type       targetID    input
    

    The source looks like this (input was letter r)

    <tr>
    <td>typeKeys</td>
    <td>//form/input</td>
    <td>r</td>
    </tr>
    <tr>
    <td>fireEvent</td>
    <td>//form/input</td>
    <td>focus</td>
    <tr>
    <td>fireEvent</td>
    <td>//form/input</td>
    <td>focus</td>
    </tr>
    <tr>
    <td>type</td>
    <td>//form/input</td>
    <td>r</td>
    </tr>
    </tr>
    <tr>
    <td>type</td>
    <td>//form/input</td>
    <td>r</td>
    </tr>
    
    0 讨论(0)
  • 2020-12-17 22:20

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

    fireEvent targetID blur

    0 讨论(0)
  • 2020-12-17 22:20

    Your solution normally is found by looking at the JavaScript code..

    An option you always have is to put in the value and manually trigger the actual OnChange event from code.

    There are an open issue about this link text Problem with FireFox Windows not being active and prevents the OnChange to be triggered.

    Try this before using typeKeys command:

    selenium.selectWindow(null);
    
    0 讨论(0)
提交回复
热议问题