1

我目前正在使用 selenium webdriver 2.35 用于在 ruby​​ 中编程的 firefox。我遇到了一个问题,我无法让 webdriver 正确关注输入字段元素。默认情况下,该字段中已经填充了一些灰色文本。当用户单击此字段时,该灰色文本应该消失并允许用户输入字段。

使用 webdriver,我将点击命令发送到该元素,它会点击,但视觉上不会发生任何事情。我还检查了活动元素,实际上它就是那个字段(单击元素后)。(我用这个来检查driver.switch_to.active_element:)

另外,我会将键发送到该字段,它会显示为灰色,或者附加到默认文本或清除该字段并发送这些键

我用过但没用的方法

1)driver.find_element(element).click

2)driver.action.move_to.element.click.perform

有没有人有什么建议?(我知道这可能听起来模棱两可,但随时问我需要更多信息)

我不确定这是否有帮助,但这是点击之前的 html(在 selenium 中使用点击功能后的结果也相同)

这是点击前的html(以及使用selenium点击功能后的结果

<html>
    <td id="ext-gen273" class="x-toolbar-cell input-container">
        <div id="ext-gen274" class="x-form-field-wrap x-form-field-trigger-wrap" style="width: 467px;">
            <input id="ext-comp-1024" class="x-form-text x-form-field autofoo-search-txtbx foo-search-dropdown x-form-empty-field" type="text" name="ext-comp-1024" autocomplete="off" size="24" style="width: 398px;"></input>
        </div>
    </td>
</html>

此 html 出现在用户手动单击该字段之后。

<html>
    <td id="ext-gen273" class="x-toolbar-cell input-container">
        <div id="ext-gen274" class="x-form-field-wrap x-form-field-trigger-wrap x-trigger-wrap-focus" style="width: 467px;">
            <input id="ext-comp-1024" class="x-form-text x-form-field autofoo-search-txtbx foo-search-dropdown x-form-focus" type="text" name="ext-comp-1024" autocomplete="off" size="24" style="width: 398px;"></input>
        </div>
    </td>
</html>

我还注意到,在用户手动单击该字段后,selenium 命令可以正常工作

4

0 回答 0