I need to press Ctrl+A keys using Selenium WebDriver. Is there any way to do it?
I checked the Selenium libraries and found that Selenium allow
By using Robot class in Java:
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Test1
{
public static void main(String[] args) throws Exception
{
WebDriver d1 = new FirefoxDriver();
d1.navigate().to("https://www.youtube.com/");
Thread.sleep(3000);
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
// Perform [Ctrl+A] Operation - it works
rb.keyPress(KeyEvent.VK_CONTROL);
rb.keyPress(KeyEvent.VK_A);
//It needs to release key after pressing
rb.keyRelease(KeyEvent.VK_A);
rb.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(3000);
}
}