Saturday, May 17, 2014

What is the alternate way to send text in textbox of webpage with out using sendKeys() method ?

Note- Use Javascript to send text.

syntax-

((JavascriptExecutor)driver).executeScript("document.getElementById('attribute value of id').value='text which you want to pass'");

ex-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WithoutSendKeys {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://accounts.google.com/ServiceLogin?sacu=1&scc=1...");
((JavascriptExecutor)driver).executeScript("document.getElementById('Email').value='sanjay'");
}
}

No comments:

Post a Comment