Saturday, 2 July 2016

Enter data in text box using JavaScript in Selenium

Sometimes, sendKeys method does not work on text boxes. In such scenarios, you can use JavascriptExecutor to set the value in edit box. Below method takes 2 arguments. It sets the value passed in second argument in text box identified as first parameter.

protected void setValueByJavaScript(WebElement element,String value) {
        ((JavascriptExecutor) driver).executeScript("arguments[0].value ='"+
value+"';", element);
    }


What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

About Me

My photo

Self-motivated software professional