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



发布了430 篇原创文章 · 获赞 415 · 访问量 925万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览