Friday 20 June 2014

using Ajax control

package TestNG;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

import com.thoughtworks.selenium.Selenium;

public class ajax {
    public WebDriver driver;
    public Selenium selenium;
   
  @Test
  public void ajaxcontrol() throws Exception {
    driver.findElement(By.id("gbqfq")).sendKeys("selenium");
   Thread.sleep(2000);
String str;
   str = driver.findElement(By.xpath("//*[@id='gsr']/table/tbody/tr[1]/td[2]")).getText();
   System.out.println(str);
   String s[] = str.split("\n");
   System.out.println(s.length);
  for (int i = 0; i < s.length; i++) {
       if (s[i].equalsIgnoreCase("selenium tutorial")) {
           System.out.println(s[i]);
           driver.findElement(By.id("gbqfq")).clear();
           driver.findElement(By.id("gbqfq")).sendKeys(s[i]);
          
       }       
    }
  }
 
  @BeforeTest
  public void beforeTest() {
  driver=new FirefoxDriver();
  driver.get("http://google.com/");
  driver.manage().window().maximize();
  }

  @AfterTest
  public void afterTest() {
  }

}

No comments:

Post a Comment