【发布时间】:2015-06-30 09:37:15
【问题描述】:
我正在尝试使用 Selenium 测试 HTML 表单。该页面通过在每个文本字段(这是HTML 中的输入标记)上使用javascript 的onFocus() 事件来验证输入数据。因此,我的代码需要确保每当我与文本字段交互时都会触发onFocus(),就像真正的用户填写表单一样。
我希望以下代码触发此事件:
this.textfield.clear();
if (value != null) {
this.textfield.sendKeys(value);
}
但是,onFocus() 事件不会触发。我试过手动点击元素
this.textfield.click()
但这也行不通。我也尝试过使用 Actions 类
this.textfield.clear();
Actions action = new Actions(driver);
action.moveToElement(this.textfield).click().sendKeys(value.toString()).perform();
但这也没有给我带来任何运气。
Selenium 中有什么方法可以确保onFocus() 事件被执行?
【问题讨论】:
标签: java javascript selenium selenium-webdriver