Tuesday 4 August 2015

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'");
}
}

1 comment:

  1. Hi Brahma,

    I have another question which i need help on, i have taken screenshots of websites using selenium web driver . I now need to write these screenshots into an excel sheet. How can i do this ?. I am already reading data from excel.

    (P.S. i am not selenium/java pro, just been using it for last 4 days , have tried and learned things on the web for one of my projects)

    ReplyDelete

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...