Firing events in leanft in Java

We can fire html events like click, change etc on any Web element using EventInfo class in LeanFT. Here is the complete example that illustrates how to fire events.
 
package leanft;

import com.hp.lft.report.Reporter;
import com.hp.lft.report.Status;
import com.hp.lft.sdk.NativeObject;
import com.hp.lft.sdk.web.*;
import org.junit.Test;

import java.util.List;

public class ChromeNativeObjectTest extends BaseTest {

    @Test
    public void test() throws Exception{

        Browser browser = BrowserFactory.launch(BrowserType.CHROME);
        try{
            //Navigate to https://www.softpost.org/selenium-test-page/
            browser.navigate("https://www.softpost.org/selenium-test-page/");
            browser.sync();

            //set value in edit box
            browser.describe(EditField.class,new EditFieldDescription.Builder()
            .id("fn").build()).setValue("Sagar");


           browser.describe(Link.class, new LinkDescription.Builder()
                    .tagName("A").innerText("Home").build()).fireEvent(EventInfoFactory.createEventInfo("click"));
            Thread.sleep(3000);


        }
        catch(AssertionError ex){
           //Report the Exception
           Reporter.reportEvent("Exception","Test failed", Status.Failed, ex);
           throw ex;
        }
        finally{
            //Close the browser
            browser.close();
        }
    }
}

Alternatively, you can also execute custom JavaScript using below syntax.
 
 String html =  browser.getPage().runJavaScript("document.body.innerHTML;"); 

To fire change event on element with id -fn, You can use below Javascript as argument to runJavaScript() method.
 
var evt = document.createEvent('HTMLEvents');
evt.initEvent ('change', true, true);
document.findElementById('fn').dispatchEvent(evt);   

Complex problems, Simple Solutions