Selenium 如何清除Intern JS中的输入字段?

Selenium 如何清除Intern JS中的输入字段?,selenium,intern,leadfoot,Selenium,Intern,Leadfoot,我已经为内联编辑表字段编写了一小段代码。当用户单击时,元素将被删除,并在其位置上创建一个输入字段。修改完成后,将删除输入字段,并创建具有新值的span元素。让我展示一些背景代码 单击之前的html代码: <div> <table id='mytable'> <thead> ... </thead> <tbody id='mybody'> ... <tr class="tr-edit even" role="row"&g

我已经为内联编辑表字段编写了一小段代码。当用户单击时,元素将被删除,并在其位置上创建一个
输入
字段。修改完成后,将删除
输入
字段,并创建具有新值的
span
元素。让我展示一些背景代码

单击之前的html代码:

<div>
 <table id='mytable'>
 <thead>
...
 </thead>
 <tbody id='mybody'>
 ...
 <tr class="tr-edit even" role="row">
  <td>escape substitution</td>
  <td>TEXT</td>
  <td>4</td>
  <td id="268435506">
   <span class="td-span-edit">hola</span>
  </td>
 </tr>
 ...
 </tbody>
 </table>
</div>
<div>
 <table id='mytable'>
 <thead>
...
 </thead>
 <tbody id='mybody'>
 ...
 <tr class="tr-edit even" role="row">
  <td>escape substitution</td>
  <td>TEXT</td>
  <td>4</td>
  <td id="268435506">
   <input class="td-input-edit" type="text" value='hola'/>
  </td>
 </tr>
 ...
 </tbody>
 </table>
</div>
问题在于测试失败,chrome和firefox都出现了异常

  • chrome:
    InvalidElementState:无效元素状态:元素必须是用户可编辑的才能清除它
  • firefox:
    未知错误:元素必须是用户可编辑的才能清除。
  • 当异常发生并且输入字段被清晰地聚焦时,我就知道了。所以你应该可以编辑它。我试图从链中删除
    .clearValue()
    调用,但正如预期的那样,断言失败


    问题:如何测试此内联编辑?

    尝试将文本字段属性“value”设置为空白,而不是使用clearValue(),然后键入新值

    .setAttribute("value", "")
    

    您看到的问题是因为您试图对错误的元素执行
    clearValue()
    ,例如id为
    268435506
    td
    元素。当用户单击
    td
    元素时,单击处理程序将删除原始
    span
    元素,并放置
    input
    元素,以便用户可以键入新值。发生这种情况时,应使用
    find*
    来“选择”适当的元素并执行相应的操作。让我用您的初始代码来说明这一点:

    tdd.test('inline editing',function(){
     return this.remote
     .findById('268435506')
        .then(function(param){
            return this.parent
                .moveMouseTo(param)
                ;
        })
        .click()
        .findByClassName('td-input-edit')
            .clearValue()
            .type('666\uE007')//enter button to end or click outside
            .executeAsync(function(done){
                promise
                    .then(function(){
                        done();
                    });
            })
        .end()
        .findByClassName('td-span-edit')
            .getVisibleText()
            .then(function(text){
                assert.strictEqual(text,
                    '666',
                    'typed value should be stored');
            })
        .end()
     .end()
        ;
    )};
    

    leadfoot中没有这样的函数调用。至少我没看到。无论如何,我发现了这个问题,我很快就会给出答案。
    tdd.test('inline editing',function(){
     return this.remote
     .findById('268435506')
        .then(function(param){
            return this.parent
                .moveMouseTo(param)
                ;
        })
        .click()
        .findByClassName('td-input-edit')
            .clearValue()
            .type('666\uE007')//enter button to end or click outside
            .executeAsync(function(done){
                promise
                    .then(function(){
                        done();
                    });
            })
        .end()
        .findByClassName('td-span-edit')
            .getVisibleText()
            .then(function(text){
                assert.strictEqual(text,
                    '666',
                    'typed value should be stored');
            })
        .end()
     .end()
        ;
    )};