Selenium WebDriver - Can we enter text without using sendKeys() ?
Selenium WebDriver Interview question and Answers
(Continued from previous question...)
Selenium WebDriver - Can we enter text without using sendKeys() ?
Yes we can enter text without using sendKeys() method. We have to use combination of javascript and wrapper classes with WebDriver extension class, check the below code-
public static void setAttribute(WebElement element, String attributeName, String value)
{ WrapsDriver wrappedElement = (WrapsDriver) element; JavascriptExecutor driver = (JavascriptExecutor)wrappedElement.getWrappedDriver(); driver.executeScript("arguments[0].setAttribute(arguments[1],arguments[2])", element, attributeName, value); }
public static void setAttribute(WebElement element, String attributeName, String value)
{
WrapsDriver wrappedElement = (WrapsDriver) element;
JavascriptExecutor driver = (JavascriptExecutor)wrappedElement.getWrappedDriver();
driver.executeScript("arguments[0].setAttribute(arguments[1],arguments[2])", element, attributeName, value);
}
call the above method in the test script and pass the text field attribute and pass the text you want to enter.
(Continued on next question...)
Other Interview Questions
|