document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package wdscripts;
  2.  
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.JavascriptExecutor;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.firefox.FirefoxDriver;
  9. import org.testng.annotations.AfterClass;
  10. import org.testng.annotations.BeforeClass;
  11. import org.testng.annotations.Test;
  12.  
  13. public class Javascript {
  14.     //create a variable for WebDriver class
  15.     public WebDriver driver;
  16.     @Test
  17.     public void testJavascript_Type() throws Exception {
  18.         //open URL
  19.         driver.get("http://www.bing.com/");
  20.         ((JavascriptExecutor)driver).executeScript("arguments[0].value=\'Nagaraju\'", driver.findElement(By.id("sb_form_q")));
  21.         Thread.sleep(5000);
  22.  
  23.     }
  24.     @BeforeClass
  25.     public void beforeClass() {
  26.         //instantiate FF browser
  27.         driver = new FirefoxDriver();
  28.         //maximize window
  29.         driver.manage().window().maximize();
  30.         //implicit wait
  31.         driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  32.  
  33.     }
  34.  
  35.     @AfterClass
  36.     public void afterClass() {
  37.         //close the browser
  38.         driver.quit();
  39.     }
  40.  
  41. }
');