I am new to Selenium. I just want to send keys to a username text box and send a tab key both at a time so that text box can check for availability of username.
This is a single line command to send the TAB key;
driver.findElement(By.id("Enter_ID")).sendKeys("\t");
I doubt for Keys.TAB
in sendKeys
method... if you want to use TAB you need to do something like below:
Actions builder = new Actions(driver);
builder.keyDown(Keys.TAB).perform()
Try this one, and then import the package:
import org.openqa.selenium.Keys;
driver.findElement(By.xpath("//*[@id='username']")).sendKeys("username");
driver.findElement(By.xpath("//*[@id='username']")).sendKeys(Keys.TAB);
driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("password");
Try using Robot
class in java for pressing TAB key. Use the below code.
driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName");
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
The simplest solution is Go to Build Path > Configure Build Path > Java Compiler and then select the 'Compiler compliance level:' to the latest one from 1.4 (probably you have this).