`
aerchi
  • 浏览: 427569 次
  • 性别: Icon_minigender_1
  • 来自: 昆明
文章分类
社区版块
存档分类
最新评论

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 justdoing what a user would do :)


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



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics