java - How to get onFocus() to fire with Selenium -


i'm trying test html form using selenium. page authenticates input data using javascript's onfocus() event on each text field (which input tag in html). such, code needs make sure onfocus() fired whenever interact text field, if real user filling out form.

i expect following code fire event:

this.textfield.clear(); if (value != null) {     this.textfield.sendkeys(value); } 

however, onfocus() event doesn't fire. i've tried manually clicking element

this.textfield.click() 

but doesn't work. i've tried using actions class

this.textfield.clear(); actions action = new actions(driver); action.movetoelement(this.textfield).click().sendkeys(value.tostring()).perform(); 

but hasn't given me luck.

is there way in selenium ensure onfocus() event executed?

you can execute javascript in browser session explicitly fire onfocus(). code in c#, there must similar in java bindings too.

((ijavascriptexecutor)driver).executescript(string.format("$('#{0}').onfocus()", elementid)); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -