文本输入元素  

概述

文本输入包括:Watir::TextFieldWatir::TextArea。请注意,任何未定义 type 属性的 Input 元素都被视为 TextField

它们分别通过调用 Browser#text_fieldBrowser#textarea 来访问。创建 TextFieldCollection 通过 Browser#text_fields 完成,创建 TextareaCollection 通过 Browser#textareas 完成。有关定位 TextFieldTextArea 元素的所有不同方法,请查看我们的 元素定位指南

它们还继承了来自标准 网页元素 的方法。

常用或特殊方法

前 3 个方法定义在 Watir::UserEditable 模块中。

标准设置器接口

TextField#setTextArea#set 接受一个 String 参数。Watir 清空字段,然后将提供的键发送到元素。

示例

browser = Watir::Browser.start 'watir.com/examples/simple_form.html'

text_field = browser.text_field(id: 'first_name')
text_field.set 'Luke'
text_field.value == 'Luke' # => true
text_field.append ' Perry'
text_field.value == 'Luke Perry' # => true
text_field.clear
text_field.value == '' # => true
text_field.append 'Luke'
text_field.value == 'Luke' # => true
text_field.set ' Perry'
text_field.value == ' Perry' # => true

browser.close

所见即所得编辑器

大多数所见即所得编辑器通过将非输入元素设置为可编辑,并使用 content-editable 属性来实现。有关更多信息,请参见 所见即所得编辑器 页面。

最后更新时间:2021 年 3 月 28 日