webdriver setfocus 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 just doing what a user would do :) 


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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值