VAIBHAV SINGH
Selenium Interview Question

Question : How to type in a textbox using Selenium?

Using SendKeys method (Its emulate typing)
User can use sendKeys(String to be entered) to enter the string in the textbox.

WebElement username = drv.findElement(By.id("Email"));
username.sendKeys("text to enter");


Using JavascriptExecutor Interface (Its simulates typing)
User can use JavascriptExecutor interface also which basically simulate typing and enter big files and text in any input box

var text = "text to input";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].value="+text, element);




Back