0

I want to open a chrome browser and then want to press tab key by robot class, not by using selenium's sendKeys but only by Robot class. Below is my code.

public static void main(String[] args) throws InterruptedException, 
AWTException {

// no need to set chrome driver path to system property as it is installed 
by brew cask
ChromeDriver d = new ChromeDriver();
d.get("http://cresconnect.crestechglobal.com//index.php?ref=");
Thread.sleep(10000);
d.findElement(By.xpath("//input[@name=\"username\"]")).sendKeys("hii bro");

Robot r = new Robot();
r.keyPress(KeyEvent.VK_TAB);
Thread.sleep(500);
r.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(500);

r.keyPress(KeyEvent.VK_TAB);
Thread.sleep(500);
r.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(500);

r.keyPress(KeyEvent.VK_TAB);
Thread.sleep(500);
r.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(5000);

}

Browser is opened correctly. Every things work fine until the line of Robot class comes. As robot class press key executed, focus from chrome window removed and chome window minimized. and there is no impact of tab on websites. Please help to resolve this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.