webdriver setfocus blur

Selenium2中模拟鼠标点击
本文讨论了在Selenium2中如何模拟用户通过手动点击鼠标来离开输入框的行为。作者指出,直接使用click方法来触发其他元素的点击事件比尝试手动触发blur事件更为有效。
On Sunday, 30 September 2012 01:31:52 UTC+1, Hava Edelstein wrote:In the IDE, I use this line:fireEvent | [element] | blur
"fireEvent" is no longer supported in Selenium 2. I know there's TypeKeys, but to my understanding, this doesn't simulate what happens if the user leaves the field by manually clicking in another field with the mouse.
If you're aiming to simulate what happens when a user leaves a field by manually clicking in another field with the mouse, that's exactly what you should do.
Assuming the field with ID someField currently has focus:
driver.findElement(By.id("someOtherField")).click()
will fire all of the relevant events on someField, and then focus someOtherField.
Alternatively, you could (again, assuming someField already has focus), do something like press the tab key:
driver.switchTo().activeElement().sendKeys(Key.TAB)

Manually firing events is a worse and more fiddly way to test than justdoing what a user would do :)


http://osdir.com/ml/selenium-users/2012-09/msg02088.html



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值