Thursday, 9 February 2017

SELENIUM: How to type text in text box field in selenium using ROBOT class



Example:
package com.rameshsoft.rameshselenium;

import java.awt.AWTException;
import java.awt.HeadlessException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

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

public class SendkeysRobot {
         
          @Test
          public void test() throws  IOException, InterruptedException, AWTException
          {
          System.setProperty("webdriver.gecko.driver", "C:\\Users\\ramesh\\Desktop\\java\\desk\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(55, TimeUnit.SECONDS); 
driver.manage().deleteAllCookies();
driver.get("https://www.gmail.com"); 
Thread.sleep(2000); 
driver.findElement(By.id("Email")).click();;

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_R);
robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_M);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_F);
robot.keyPress(KeyEvent.VK_T); 
driver.findElement(By.id("next")).click();
Thread.sleep(2000); 
driver.findElement(By.id("Passwd")).click(); 
Robot robot1 = new Robot();
robot1.keyPress(KeyEvent.VK_A);
robot1.keyPress(KeyEvent.VK_B);
robot1.keyPress(KeyEvent.VK_C);
robot1.keyPress(KeyEvent.VK_D);
robot1.keyPress(KeyEvent.VK_5);

driver.findElement(By.id("signIn")).click();
           
}
}

1 comment:

  1. Blackjack Review - DMC
    Blackjack in MSN is a high-stakes game in which the player will either be the banker, or the dealer. The 부천 출장샵 table 과천 출장마사지 game has 군포 출장마사지 a chance 광명 출장샵 of 의왕 출장마사지 winning the $100 jackpot,

    ReplyDelete